Title
Disallow annotations on block-scope externs and non-unique friend declarations
Status
review
Section
9.13.12 [dcl.attr.annotation]
Submitter
Dan Katz

Created on 2025-11-15.00:00:00 last changed 5 days ago

Messages

Date: 2026-02-06.22:00:31

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
  • 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 of D is a friend declaration that is a definition.
Date: 2026-02-06.22:00:31

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.

Date: 2026-02-06.22:00:31

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.
Date: 2026-02-06.22:00:31

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.
Date: 2025-11-15.00:00:00

(From submission #809.)

Be conservative and disallow annotations on block-scope externs.

History
Date User Action Args
2026-02-06 22:00:31adminsetmessages: + msg8471
2026-02-06 22:00:31adminsetmessages: + msg8470
2026-02-06 22:00:31adminsetstatus: open -> review
2025-11-17 23:24:38adminsetmessages: + msg8392
2025-11-17 23:24:38adminsetmessages: + msg8391
2025-11-15 00:00:00admincreate