This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
[dcl.decl.general]
# 9 Declarations [[dcl]](./#dcl)
## 9.3 Declarators [[dcl.decl]](dcl.decl#general)
### 9.3.1 General [dcl.decl.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L2376)
A declarator declares a single variable, function, or type, within a declaration[.](#1.sentence-1)
The[*init-declarator-list*](#nt:init-declarator-list "9.3.1General[dcl.decl.general]") appearing in a [*simple-declaration*](dcl.pre#nt:simple-declaration "9.1Preamble[dcl.pre]") is a comma-separated sequence of declarators,
each of which can have an initializer[.](#1.sentence-2)
[init-declarator-list:](#nt:init-declarator-list "9.3.1General[dcl.decl.general]")
[*init-declarator*](#nt:init-declarator "9.3.1General[dcl.decl.general]")
[*init-declarator-list*](#nt:init-declarator-list "9.3.1General[dcl.decl.general]") , [*init-declarator*](#nt:init-declarator "9.3.1General[dcl.decl.general]")
[init-declarator:](#nt:init-declarator "9.3.1General[dcl.decl.general]")
[*declarator*](#nt:declarator "9.3.1General[dcl.decl.general]") [*initializer*](dcl.init.general#nt:initializer "9.5.1General[dcl.init.general]")
[*declarator*](#nt:declarator "9.3.1General[dcl.decl.general]") [*requires-clause*](temp.pre#nt:requires-clause "13.1Preamble[temp.pre]")opt [*function-contract-specifier-seq*](dcl.contract.func#nt:function-contract-specifier-seq "9.4.1General[dcl.contract.func]")opt
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L2396)
In all contexts, a [*declarator*](#nt:declarator "9.3.1General[dcl.decl.general]") is interpreted as given below[.](#2.sentence-1)
Where an [*abstract-declarator*](dcl.name#nt:abstract-declarator "9.3.2Type names[dcl.name]") can be used (or omitted)
in place of a [*declarator*](#nt:declarator "9.3.1General[dcl.decl.general]") ([[dcl.fct]](dcl.fct "9.3.4.6Functions"), [[except.pre]](except.pre "14.1Preamble")),
it is as if a unique identifier were included in
the appropriate place ([[dcl.name]](dcl.name "9.3.2Type names"))[.](#2.sentence-2)
The preceding specifiers indicate
the type, storage duration, linkage, or other properties
of the entity or entities being declared[.](#2.sentence-3)
Each declarator specifies one entity and
(optionally) names it and/or
modifies the type of the specifiers with operators such as* (pointer to) and () (function returning)[.](#2.sentence-4)
[*Note [1](#note-1)*:
An [*init-declarator*](#nt:init-declarator "9.3.1General[dcl.decl.general]") can also specify an initializer ([[dcl.init]](dcl.init "9.5Initializers"))[.](#2.sentence-5)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L2413)
Each [*init-declarator*](#nt:init-declarator "9.3.1General[dcl.decl.general]") or [*member-declarator*](class.mem.general#nt:member-declarator "11.4.1General[class.mem.general]") in a declaration is analyzed separately as if it were in a declaration by itself[.](#3.sentence-1)
[*Note [2](#note-2)*:
A declaration with several declarators is usually equivalent to the corresponding
sequence of declarations each with a single declarator[.](#3.sentence-2)
That is,T D1, D2, ... Dn; is usually equivalent toT D1; T D2; ... T Dn; where T is a [*decl-specifier-seq*](dcl.spec.general#nt:decl-specifier-seq "9.2.1General[dcl.spec.general]") and each Di is
an [*init-declarator*](#nt:init-declarator "9.3.1General[dcl.decl.general]") or [*member-declarator*](class.mem.general#nt:member-declarator "11.4.1General[class.mem.general]")[.](#3.sentence-3)
One exception is when a name introduced by one of the[*declarator*](#nt:declarator "9.3.1General[dcl.decl.general]")*s* hides a type name used by the[*decl-specifier*](dcl.spec.general#nt:decl-specifier "9.2.1General[dcl.spec.general]")*s*, so that when the same[*decl-specifier*](dcl.spec.general#nt:decl-specifier "9.2.1General[dcl.spec.general]")*s* are used in a subsequent declaration,
they do not have the same meaning, as instruct S { /* ... */ };
S S, T; // declare two instances of struct S which is not equivalent tostruct S { /* ... */ };
S S;
S T; // error
Another exception is when T is auto ([[dcl.spec.auto]](dcl.spec.auto "9.2.9.7Placeholder type specifiers")),
for example:auto i = 1, j = 2.0; // error: deduced types for i and j do not match as opposed toauto i = 1; // OK, i deduced to have type intauto j = 2.0; // OK, j deduced to have type double
— *end note*]
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L2456)
The optional [*requires-clause*](temp.pre#nt:requires-clause "13.1Preamble[temp.pre]") in an[*init-declarator*](#nt:init-declarator "9.3.1General[dcl.decl.general]") or [*member-declarator*](class.mem.general#nt:member-declarator "11.4.1General[class.mem.general]") shall be present only if the declarator declares a
templated function ([[temp.pre]](temp.pre "13.1Preamble"))[.](#4.sentence-1)
When present after a declarator, the [*requires-clause*](temp.pre#nt:requires-clause "13.1Preamble[temp.pre]") is called the [*trailing* ](#def:requires-clause,trailing "9.3.1General[dcl.decl.general]")*[*requires-clause*](temp.pre#nt:requires-clause "13.1Preamble[temp.pre]")*[.](#4.sentence-2)
The trailing [*requires-clause*](temp.pre#nt:requires-clause "13.1Preamble[temp.pre]") introduces the[*constraint-expression*](temp.constr.decl#nt:constraint-expression "13.5.3Constrained declarations[temp.constr.decl]") that results from interpreting
its [*constraint-logical-or-expression*](temp.pre#nt:constraint-logical-or-expression "13.1Preamble[temp.pre]") as a[*constraint-expression*](temp.constr.decl#nt:constraint-expression "13.5.3Constrained declarations[temp.constr.decl]")[.](#4.sentence-3)
[*Example [1](#example-1)*: void f1(int a) requires true; // error: non-templated functiontemplate<typename T>auto f2(T a) -> bool requires true; // OKtemplate<typename T>auto f3(T a) requires true -> bool; // error: [*requires-clause*](temp.pre#nt:requires-clause "13.1Preamble[temp.pre]") precedes [*trailing-return-type*](#nt:trailing-return-type "9.3.1General[dcl.decl.general]")void (*pf)() requires true; // error: constraint on a variablevoid g(int (*)() requires true); // error: constraint on a [*parameter-declaration*](dcl.fct#nt:parameter-declaration "9.3.4.6Functions[dcl.fct]")auto* p = new void(*)(char) requires true; // error: not a function declaration — *end example*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L2485)
The optional [*function-contract-specifier-seq*](dcl.contract.func#nt:function-contract-specifier-seq "9.4.1General[dcl.contract.func]") ([[dcl.contract.func]](dcl.contract.func "9.4.1General"))
in an [*init-declarator*](#nt:init-declarator "9.3.1General[dcl.decl.general]") shall be present only if
the [*declarator*](#nt:declarator "9.3.1General[dcl.decl.general]") declares a function[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L2491)
Declarators have the syntax
[declarator:](#nt:declarator "9.3.1General[dcl.decl.general]")
[*ptr-declarator*](#nt:ptr-declarator "9.3.1General[dcl.decl.general]")
[*noptr-declarator*](#nt:noptr-declarator "9.3.1General[dcl.decl.general]") [*parameters-and-qualifiers*](#nt:parameters-and-qualifiers "9.3.1General[dcl.decl.general]") [*trailing-return-type*](#nt:trailing-return-type "9.3.1General[dcl.decl.general]")
[ptr-declarator:](#nt:ptr-declarator "9.3.1General[dcl.decl.general]")
[*noptr-declarator*](#nt:noptr-declarator "9.3.1General[dcl.decl.general]")
[*ptr-operator*](#nt:ptr-operator "9.3.1General[dcl.decl.general]") [*ptr-declarator*](#nt:ptr-declarator "9.3.1General[dcl.decl.general]")
[noptr-declarator:](#nt:noptr-declarator "9.3.1General[dcl.decl.general]")
[*declarator-id*](#nt:declarator-id "9.3.1General[dcl.decl.general]") [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]")opt
[*noptr-declarator*](#nt:noptr-declarator "9.3.1General[dcl.decl.general]") [*parameters-and-qualifiers*](#nt:parameters-and-qualifiers "9.3.1General[dcl.decl.general]")
[*noptr-declarator*](#nt:noptr-declarator "9.3.1General[dcl.decl.general]") [ [*constant-expression*](expr.const#nt:constant-expression "7.7Constant expressions[expr.const]")opt ] [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]")opt
( [*ptr-declarator*](#nt:ptr-declarator "9.3.1General[dcl.decl.general]") )
[parameters-and-qualifiers:](#nt:parameters-and-qualifiers "9.3.1General[dcl.decl.general]")
( [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6Functions[dcl.fct]") ) [*cv-qualifier-seq*](#nt:cv-qualifier-seq "9.3.1General[dcl.decl.general]")opt
[*ref-qualifier*](#nt:ref-qualifier "9.3.1General[dcl.decl.general]")opt [*noexcept-specifier*](except.spec#nt:noexcept-specifier "14.5Exception specifications[except.spec]")opt [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]")opt
[trailing-return-type:](#nt:trailing-return-type "9.3.1General[dcl.decl.general]")
-> [*type-id*](dcl.name#nt:type-id "9.3.2Type names[dcl.name]")
[ptr-operator:](#nt:ptr-operator "9.3.1General[dcl.decl.general]")
* [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]")opt [*cv-qualifier-seq*](#nt:cv-qualifier-seq "9.3.1General[dcl.decl.general]")opt
& [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]")opt
&& [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]")opt
[*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3Qualified names[expr.prim.id.qual]") * [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1Attribute syntax and semantics[dcl.attr.grammar]")opt [*cv-qualifier-seq*](#nt:cv-qualifier-seq "9.3.1General[dcl.decl.general]")opt
[cv-qualifier-seq:](#nt:cv-qualifier-seq "9.3.1General[dcl.decl.general]")
[*cv-qualifier*](#nt:cv-qualifier "9.3.1General[dcl.decl.general]") [*cv-qualifier-seq*](#nt:cv-qualifier-seq "9.3.1General[dcl.decl.general]")opt
[cv-qualifier:](#nt:cv-qualifier "9.3.1General[dcl.decl.general]")
const
volatile
[ref-qualifier:](#nt:ref-qualifier "9.3.1General[dcl.decl.general]")
&
&&
[declarator-id:](#nt:declarator-id "9.3.1General[dcl.decl.general]")
...opt [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1General[expr.prim.id.general]")