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

Created on 2025-10-01.00:00:00 last changed 1 month ago

Messages

Date: 2025-11-08.02:51:57

Proposed resolution (reviewed by CWG 2025-11-07):

  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] paragraph 2 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. Insert before 9.13.1 [dcl.attr.grammar] paragraph 5 as follows:

    [ Note: Unless otherwise specified, an attribute-token specified in this document cannot be used as a macro name (15.7.1 [cpp.replace.general]). -- end note ]

    An annotation followed by an ellipsis is a pack expansion (13.7.4 [temp.variadic]).

  4. 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.
  5. 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-11-08 02:51:57adminsetstatus: ready -> review
2025-11-06 23:04:52adminsetstatus: tentatively ready -> ready
2025-11-04 22:23:01adminsetstatus: review -> tentatively ready
2025-11-04 06:01:49adminsetstatus: open -> review
2025-10-11 14:00:52adminsetmessages: + msg8151
2025-10-01 00:00:00admincreate