Title
Clarify macro treatment of identifiers with special meaning
Status
open
Section
15.7.1 [cpp.replace.general]
Submitter
US

Created on 2025-10-01.00:00:00 last changed 2 days ago

Messages

Date: 2025-10-11.14:00:52

Suggested resolution:

  1. Insert before 5.11 [lex.name] paragraph 3 as follows:

    [ Note: Identifiers with special meaning cannot be used as macro names (15.7.1 [cpp.replace.general]). -- end note ]

    In addition, some identifiers appearing as a token or preprocessing-token are reserved for use by C++ implementations and shall not be used otherwise; no diagnostic is required. ...

  2. Insert before 5.12 [lex.key] as follows:

    [ Note: Keywords cannot be used as macro names (15.7.1 [cpp.replace.general]). -- end note ]

    Furthermore, the alternative representations shown in Table 6 for certain operators and punctuators (5.9 [lex.digraph]) are reserved and shall not be used otherwise.

  3. Change in 15.7.1 [cpp.replace.general] paragraph 9 as follows:

    A translation unit shall not #define or #undef names lexically identical to keywords (5.12 [lex.key]), to the identifiers listed in Table 4, or to the attribute-tokens described in 9.13 [dcl.attr], except that the names likely and unlikely may be defined as function-like macros.
  4. Move C.1.6 [diff.cpp23.library] paragraph 2 to a new clause C.1.5+ "Clause 15 preprocessing directives" and change as follows:

    Affected subclause: 16.4.6.3 [res.on.macro.definitions] 15.7.1 [cpp.replace.general]
    Change: Additional restrictions on macro names.
    Rationale: Avoid hard to diagnose or non-portable constructs.
    Effect on original feature: Names of special identifiers identifiers with special meaning (5.11 [lex.name]) may not be used as macro names. Valid C++ 2023 code that defines replaceable_if_eligible or trivially_relocatable_if_eligible as macros is invalid in this revision of C++.
Date: 2025-10-01.00:00:00
N5028 comment USĀ 57-105

Subclause C.1.6 [diff.cpp23.library] paragraph 2 specifies:

Affected subclause: 16.4.6.3 [res.on.macro.definitions]
Change: Additional restrictions on macro names.
Rationale: Avoid hard to diagnose or non-portable constructs.
Effect on original feature: Names of special identifiers may not be used as macro names. Valid C++ 2023 code that defines replaceable_if_eligible or trivially_relocatable_if_eligible as macros is invalid in this revision of C++.

The restriction on defining keywords and identifiers with special meaning as macros was moved to 15.7.1 [cpp.replace.general] paragraph 9.

History
Date User Action Args
2025-10-11 14:00:52adminsetmessages: + msg8151
2025-10-01 00:00:00admincreate