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

2026-02-06


3124. Disallow annotations on block-scope externs and non-unique friend declarations

Section: 9.13.12  [dcl.attr.annotation]     Status: review     Submitter: Dan Katz     Date: 2025-11-15

(From submission #809.)

Be conservative and disallow annotations on block-scope externs.

Suggested resolution (option 1, 2025-11): [SUPERSEDED]

  1. Change in 9.13.1 [dcl.attr.grammar] paragraph 6 as follows:

    Each attribute-specifier-seq is said to appertain to some entity or statement, identified by the syntactic context where it appears (Clause Clause 8 [stmt], Clause Clause 9 [dcl], 9.3 [dcl.decl]). If an attribute-specifier-seq that appertains to some entity or statement contains an attribute or alignment-specifier that is not allowed to apply to that entity or statement, the program is ill-formed. If an attribute-specifier-seq appertains to a friend declaration (11.8.4 [class.friend]), that declaration shall be a definition. Furthermore, if an annotation applies to a friend declaration D, or to a function parameter declaration in the function-declarator (if any) of D, then for any other declaration D' of the entity declared by D, neither D nor D' shall be reachable from the other.
  2. Change in 9.13.12 [dcl.attr.annotation] paragraph 1 as follows:

    An annotation may be applied to any a declaration D of a type, type alias, variable, function, namespace, enumerator, base-specifier, or non-static data member. If an annotation applies to a declaration D, or to a function parameter declaration in the function-declarator (if any) of D, then the host scope of D (6.4.1 [basic.scope.scope]) shall be the target scope of D.

Possible resolution (option 2, 2025-11): [SUPERSEDED]

  1. Change in 9.13.12 [dcl.attr.annotation] paragraph 1 as follows:

    The surrounding declaration of a declaration D is
    • D' if D is a function parameter declaration in a function-declarator of a function declaration D' and
    • D otherwise.
    An annotation may be applied to any a declaration D of a type, type alias, variable, function, namespace, enumerator, base-specifier, or non-static data member, unless
    • the host scope of the surrounding declaration of D differs from its target scope or
    • the surrounding declaration D' of D is a friend declaration and another declaration for the entity declared by D' is reachable from D' or vice versa.

CWG 2026-02-06

CWG preferred the wording of option 2. Instead of the condition involving mutual reachability, CWG preferred the more traditional "is a definition" restriction.

Proposed resolution (2026-02-06)

Change in 9.13.12 [dcl.attr.annotation] paragraph 1 as follows:

The surrounding declaration of a declaration D is
An annotation may be applied to any a declaration D of a type, type alias, variable, function, namespace, enumerator, base-specifier, or non-static data member, unless