Files
cppdraft_translate/cppdraft/dcl/attr/annotation.md
2025-10-25 03:02:53 +03:00

58 lines
2.2 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[dcl.attr.annotation]
# 9 Declarations [[dcl]](./#dcl)
## 9.13 Attributes [[dcl.attr]](dcl.attr#annotation)
### 9.13.12 Annotations [dcl.attr.annotation]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L10191)
An annotation may be applied to any declaration of a
type,
type alias,
variable,
function,
namespace,
enumerator,[*base-specifier*](class.derived.general#nt:base-specifier "11.7.1General[class.derived.general]"), or
non-static data member[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L10202)
Let E be the expressionstd::meta::reflect_constant([*constant-expression*](expr.const#nt:constant-expression "7.7Constant expressions[expr.const]"))[.](#2.sentence-1)
E shall be a constant expression;
the result of E is the [*underlying constant*](#def:constant,underlying "9.13.12Annotations[dcl.attr.annotation]") of the annotation[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L10208)
Each [*annotation*](dcl.attr.grammar#nt:annotation "9.13.1Attribute syntax and semantics[dcl.attr.grammar]") produces a unique annotation[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L10211)
Substituting into an [*annotation*](dcl.attr.grammar#nt:annotation "9.13.1Attribute syntax and semantics[dcl.attr.grammar]") is not in the immediate context[.](#4.sentence-1)
[*Example [1](#example-1)*:
[[=1]] void f();[[=2, =3, =2]] void g();void g [[=4, =2]] ();f has one annotation
and g has five annotations[.](#4.sentence-2)
These can be queried with metafunctions
such as std::meta::annotations_of ([[meta.reflection.annotation]](meta.reflection.annotation "21.4.18Annotation reflection"))[.](#4.sentence-3)
— *end example*]
[*Example [2](#example-2)*: template<class T>[[=T::type()]] void f(T t);
void f(int);
void g() { f(0); // OK f('0'); // error, substituting into the annotation results in an invalid expression} — *end example*]