Title
Uniqueness of annotations
Status
open
Section
9.13.12 [dcl.attr.annotation]
Submitter
Barry Revzin

Created on 2025-12-01.00:00:00 last changed 2 weeks ago

Messages

Date: 2026-02-21.09:24:24

Suggested resolution:

Change in 9.13.12 [dcl.attr.annotation] paragraph 3 and paragraph 4 as follows:

(3) Each annotation produces a unique annotation.

Substituting into an annotation is not in the immediate context.

[Example:
  [[=1]] void f();
  [[=2, =3, =2]] void g();
  void g [[=4, =2]] ();
f has one annotation and g has five annotations. These can be queried with metafunctions such as std::meta::annotations_of (21.4.12 [meta.reflection.annotation]). —end example]
[Example:
  template<int> int x [[=1]];
  static_assert(annotations_of(^^x<0>) != annotations_of(^^x<1>));   // OK
-- end example]

(4) Substituting into an annotation is not in the immediate context.

[Example:

  template<class T>
  [[=T::type()]] void f(T t);
  void f(int);
  void g() {
    f(0);       // OK
    f('0');     // error, ...
  }
-- end example]
Date: 2025-12-01.00:00:00

(From submission #825.)

Consider:

  template<int> int x [[=1]];
  template<int A> int y [[=A]];
  static_assert(annotations_of(^^x<0>) == annotations_of(^^x<1>)); // #1
  static_assert(annotations_of(^^y<0>) == annotations_of(^^y<1>)); // #2

Subclause 9.13.12 [dcl.attr.annotation] paragraph 3 specifies:

Each annotation produces a unique annotation.

It is unclear whether each instantiation of a template creates a distinct annotation.

History
Date User Action Args
2026-02-21 09:24:24adminsetmessages: + msg8486
2025-12-01 00:00:00admincreate