Skip to content

CWG3018 [cpp.cond] Ambiguous validity of defined in __has_embed #694

Description

@hubert-reinterpretcast

Full name of submitter (unless configured in github; will be published with the issue): Hubert Tong

Reference (section label): cpp.cond

Link to reflector thread (if any): N/A

Issue description:
Consider (with the proposed offset parameter for a more plausible use case):

#if __has_embed(__FILE__ offset(\
  defined(WANT_4K_SOURCE) ? 4095 : 0\
)) == __STDC_EMBED_EMPTY__
#error Desired source not found
#endif

It is unclear whether the above is ill-formed due to https://wg21.link/cpp.embed.param.limit#1 because https://wg21.link/cpp.cond#12 can be read as saying that the evaluation of the defined-macro-expression has occurred prior to the evaluation of the has-embed-expression.

Suggested resolution:
Add a restriction that

A defined-macro-expression shall not appear within a has-embed-expression.

"Editor's" note: This is for consistency with the restriction in the context of #embed, which is (in turn) motivated by the special macro expansion logic associated with defined only in the [cpp.cond] context. Since we are already in the [cpp.cond] context for __has_embed, there is no major design barrier for specifying that the defined-macro-expression‌s are evaluated first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions