This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 117a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-04-13


3018. Validity of defined in __has_embed

Section: 15.2  [cpp.cond]     Status: open     Submitter: Hubert Tong     Date: 2025-03-24

(From submission #694.)

Is the use of defined valid in __has_embed? It is not valid in cases where it would be interpreted by the #if rules in #embed; see 15.4.2.1 [cpp.embed.param.limit] paragraph 1.

To avoid confusion, defined should also be prohibited inside __has_embed.

Possible resolution:

  1. Change in 15.2 [cpp.cond] paragraph 1 as follows:

    The expression that controls conditional inclusion shall be an integral constant expression except that identifiers (including those lexically identical to keywords) are interpreted as described below123 and it may contain zero or more defined-macro-expressions, has-include-expressions, has-attribute-expressions, and/or has-embed-expressions as unary operator expressions. A defined-macro-expression shall not appear within a has-include-expression or has-embed-expression.
  2. Change in 15.4.2.1 [cpp.embed.param.limit] paragraph 1 as follows:

    An embed-parameter of the form limit ( pp-balanced-token-seq ) specifies the maximum possible number of elements in the comma-delimited list. It shall appear at most once in the embed-parameter-seq. The preprocessing token defined shall not appear in the constant-expression pp-balanced-token-seq.

    The pp-balanced-token-seq is evaluated as a constant-expression using the rules as described in conditional inclusion (15.2 [cpp.cond]), but without being processed as in normal text an additional time.