- tmp/tmp5qmhtxrn/{from.md → to.md} +111 -58
tmp/tmp5qmhtxrn/{from.md → to.md}
RENAMED
|
@@ -9,25 +9,35 @@ declaration-seq:
|
|
| 9 |
declaration-seq declaration
|
| 10 |
```
|
| 11 |
|
| 12 |
``` bnf
|
| 13 |
declaration:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
block-declaration
|
| 15 |
nodeclspec-function-declaration
|
| 16 |
function-definition
|
| 17 |
template-declaration
|
| 18 |
deduction-guide
|
| 19 |
-
explicit-instantiation
|
| 20 |
-
explicit-specialization
|
| 21 |
-
export-declaration
|
| 22 |
linkage-specification
|
| 23 |
namespace-definition
|
| 24 |
empty-declaration
|
| 25 |
attribute-declaration
|
| 26 |
module-import-declaration
|
| 27 |
```
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
``` bnf
|
| 30 |
block-declaration:
|
| 31 |
simple-declaration
|
| 32 |
asm-declaration
|
| 33 |
namespace-alias-definition
|
|
@@ -79,10 +89,16 @@ attribute-declaration:
|
|
| 79 |
[[temp.deduct.guide]]; *namespace-definition*s are described in
|
| 80 |
[[namespace.def]], *using-declaration*s are described in
|
| 81 |
[[namespace.udecl]] and *using-directive*s are described in
|
| 82 |
[[namespace.udir]]. — *end note*]
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
A *simple-declaration* or *nodeclspec-function-declaration* of the form
|
| 85 |
|
| 86 |
``` bnf
|
| 87 |
attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ init-declarator-listₒₚₜ ';'
|
| 88 |
```
|
|
@@ -93,109 +109,146 @@ are described in [[dcl.spec]]. *declarator*s, the components of an
|
|
| 93 |
*init-declarator-list*, are described in [[dcl.decl]]. The
|
| 94 |
*attribute-specifier-seq* appertains to each of the entities declared by
|
| 95 |
the *declarator*s of the *init-declarator-list*.
|
| 96 |
|
| 97 |
[*Note 2*: In the declaration for an entity, attributes appertaining to
|
| 98 |
-
that entity
|
| 99 |
*declarator-id* for that declaration. — *end note*]
|
| 100 |
|
| 101 |
[*Example 1*:
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
[[noreturn]] void f [[noreturn]] (); // OK
|
| 105 |
```
|
| 106 |
|
| 107 |
— *end example*]
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
that are *not* nested within scopes nested within the declaration.
|
| 120 |
|
| 121 |
In a *simple-declaration*, the optional *init-declarator-list* can be
|
| 122 |
-
omitted only when declaring a class [[class]] or enumeration
|
| 123 |
[[dcl.enum]], that is, when the *decl-specifier-seq* contains either a
|
| 124 |
*class-specifier*, an *elaborated-type-specifier* with a *class-key*
|
| 125 |
[[class.name]], or an *enum-specifier*. In these cases and whenever a
|
| 126 |
*class-specifier* or *enum-specifier* is present in the
|
| 127 |
-
*decl-specifier-seq*, the identifiers in these specifiers are
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
or shall redeclare a name introduced by a previous declaration.
|
| 132 |
|
| 133 |
[*Example 2*:
|
| 134 |
|
| 135 |
``` cpp
|
| 136 |
enum { }; // error
|
| 137 |
typedef class { }; // error
|
| 138 |
```
|
| 139 |
|
| 140 |
— *end example*]
|
| 141 |
|
| 142 |
-
In a *static_assert-declaration*, the *constant-expression* shall be a
|
| 143 |
-
contextually converted constant expression of type `bool`
|
| 144 |
-
[[expr.const]]. If the value of the expression when so converted is
|
| 145 |
-
`true`, the declaration has no effect. Otherwise, the program is
|
| 146 |
-
ill-formed, and the resulting diagnostic message [[intro.compliance]]
|
| 147 |
-
shall include the text of the *string-literal*, if one is supplied,
|
| 148 |
-
except that characters not in the basic source character set
|
| 149 |
-
[[lex.charset]] are not required to appear in the diagnostic message.
|
| 150 |
-
|
| 151 |
-
[*Example 3*:
|
| 152 |
-
|
| 153 |
-
``` cpp
|
| 154 |
-
static_assert(sizeof(int) == sizeof(void*), "wrong pointer size");
|
| 155 |
-
```
|
| 156 |
-
|
| 157 |
-
— *end example*]
|
| 158 |
-
|
| 159 |
-
An *empty-declaration* has no effect.
|
| 160 |
-
|
| 161 |
A *simple-declaration* with an *identifier-list* is called a *structured
|
| 162 |
-
binding declaration* [[dcl.struct.bind]].
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
The *initializer* shall be of the form “`=` *assignment-expression*”, of
|
| 166 |
the form “`{` *assignment-expression* `}`”, or of the form “`(`
|
| 167 |
*assignment-expression* `)`”, where the *assignment-expression* is of
|
| 168 |
array or non-union class type.
|
| 169 |
|
| 170 |
-
Each *init-declarator* in the *init-declarator-list* contains exactly
|
| 171 |
-
one *declarator-id*, which is the name declared by that
|
| 172 |
-
*init-declarator* and hence one of the names declared by the
|
| 173 |
-
declaration. The *defining-type-specifier*s [[dcl.type]] in the
|
| 174 |
-
*decl-specifier-seq* and the recursive *declarator* structure of the
|
| 175 |
-
*init-declarator* describe a type [[dcl.meaning]], which is then
|
| 176 |
-
associated with the name being declared by the *init-declarator*.
|
| 177 |
-
|
| 178 |
If the *decl-specifier-seq* contains the `typedef` specifier, the
|
| 179 |
-
declaration is
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
[[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
Syntactic components beyond those found in the general form of
|
| 187 |
-
declaration are added to a function declaration to make a
|
| 188 |
*function-definition*. An object declaration, however, is also a
|
| 189 |
definition unless it contains the `extern` specifier and has no
|
| 190 |
initializer [[basic.def]]. An object definition causes storage of
|
| 191 |
appropriate size and alignment to be reserved and any appropriate
|
| 192 |
initialization [[dcl.init]] to be done.
|
| 193 |
|
| 194 |
A *nodeclspec-function-declaration* shall declare a constructor,
|
| 195 |
destructor, or conversion function.
|
| 196 |
|
| 197 |
-
[*Note
|
|
|
|
|
|
|
| 198 |
*template-declaration* [[temp.pre]], *explicit-instantiation*
|
| 199 |
[[temp.explicit]], or *explicit-specialization*
|
| 200 |
[[temp.expl.spec]]. — *end note*]
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
declaration-seq declaration
|
| 10 |
```
|
| 11 |
|
| 12 |
``` bnf
|
| 13 |
declaration:
|
| 14 |
+
name-declaration
|
| 15 |
+
special-declaration
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
``` bnf
|
| 19 |
+
name-declaration:
|
| 20 |
block-declaration
|
| 21 |
nodeclspec-function-declaration
|
| 22 |
function-definition
|
| 23 |
template-declaration
|
| 24 |
deduction-guide
|
|
|
|
|
|
|
|
|
|
| 25 |
linkage-specification
|
| 26 |
namespace-definition
|
| 27 |
empty-declaration
|
| 28 |
attribute-declaration
|
| 29 |
module-import-declaration
|
| 30 |
```
|
| 31 |
|
| 32 |
+
``` bnf
|
| 33 |
+
special-declaration:
|
| 34 |
+
explicit-instantiation
|
| 35 |
+
explicit-specialization
|
| 36 |
+
export-declaration
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
``` bnf
|
| 40 |
block-declaration:
|
| 41 |
simple-declaration
|
| 42 |
asm-declaration
|
| 43 |
namespace-alias-definition
|
|
|
|
| 89 |
[[temp.deduct.guide]]; *namespace-definition*s are described in
|
| 90 |
[[namespace.def]], *using-declaration*s are described in
|
| 91 |
[[namespace.udecl]] and *using-directive*s are described in
|
| 92 |
[[namespace.udir]]. — *end note*]
|
| 93 |
|
| 94 |
+
Certain declarations contain one or more scopes [[basic.scope.scope]].
|
| 95 |
+
Unless otherwise stated, utterances in [[dcl.dcl]] about components in,
|
| 96 |
+
of, or contained by a declaration or subcomponent thereof refer only to
|
| 97 |
+
those components of the declaration that are *not* nested within scopes
|
| 98 |
+
nested within the declaration.
|
| 99 |
+
|
| 100 |
A *simple-declaration* or *nodeclspec-function-declaration* of the form
|
| 101 |
|
| 102 |
``` bnf
|
| 103 |
attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ init-declarator-listₒₚₜ ';'
|
| 104 |
```
|
|
|
|
| 109 |
*init-declarator-list*, are described in [[dcl.decl]]. The
|
| 110 |
*attribute-specifier-seq* appertains to each of the entities declared by
|
| 111 |
the *declarator*s of the *init-declarator-list*.
|
| 112 |
|
| 113 |
[*Note 2*: In the declaration for an entity, attributes appertaining to
|
| 114 |
+
that entity can appear at the start of the declaration and after the
|
| 115 |
*declarator-id* for that declaration. — *end note*]
|
| 116 |
|
| 117 |
[*Example 1*:
|
| 118 |
|
| 119 |
``` cpp
|
| 120 |
[[noreturn]] void f [[noreturn]] (); // OK
|
| 121 |
```
|
| 122 |
|
| 123 |
— *end example*]
|
| 124 |
|
| 125 |
+
If a *declarator-id* is a name, the *init-declarator* and (hence) the
|
| 126 |
+
declaration introduce that name.
|
| 127 |
|
| 128 |
+
[*Note 3*: Otherwise, the *declarator-id* is a *qualified-id* or names
|
| 129 |
+
a destructor or its *unqualified-id* is a *template-id* and no name is
|
| 130 |
+
introduced. — *end note*]
|
| 131 |
+
|
| 132 |
+
The *defining-type-specifier*s [[dcl.type]] in the *decl-specifier-seq*
|
| 133 |
+
and the recursive *declarator* structure describe a type
|
| 134 |
+
[[dcl.meaning]], which is then associated with the *declarator-id*.
|
|
|
|
| 135 |
|
| 136 |
In a *simple-declaration*, the optional *init-declarator-list* can be
|
| 137 |
+
omitted only when declaring a class [[class.pre]] or enumeration
|
| 138 |
[[dcl.enum]], that is, when the *decl-specifier-seq* contains either a
|
| 139 |
*class-specifier*, an *elaborated-type-specifier* with a *class-key*
|
| 140 |
[[class.name]], or an *enum-specifier*. In these cases and whenever a
|
| 141 |
*class-specifier* or *enum-specifier* is present in the
|
| 142 |
+
*decl-specifier-seq*, the identifiers in these specifiers are also
|
| 143 |
+
declared (as *class-name*s, *enum-name*s, or *enumerator*s, depending on
|
| 144 |
+
the syntax). In such cases, the *decl-specifier-seq* shall (re)introduce
|
| 145 |
+
one or more names into the program.
|
|
|
|
| 146 |
|
| 147 |
[*Example 2*:
|
| 148 |
|
| 149 |
``` cpp
|
| 150 |
enum { }; // error
|
| 151 |
typedef class { }; // error
|
| 152 |
```
|
| 153 |
|
| 154 |
— *end example*]
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
A *simple-declaration* with an *identifier-list* is called a *structured
|
| 157 |
+
binding declaration* [[dcl.struct.bind]]. Each *decl-specifier* in the
|
| 158 |
+
*decl-specifier-seq* shall be `static`, `thread_local`, `auto`
|
| 159 |
+
[[dcl.spec.auto]], or a *cv-qualifier*.
|
| 160 |
+
|
| 161 |
+
[*Example 3*:
|
| 162 |
+
|
| 163 |
+
``` cpp
|
| 164 |
+
template<class T> concept C = true;
|
| 165 |
+
C auto [x, y] = std::pair{1, 2}; // error: constrained placeholder-type-specifier
|
| 166 |
+
// not permitted for structured bindings
|
| 167 |
+
```
|
| 168 |
+
|
| 169 |
+
— *end example*]
|
| 170 |
+
|
| 171 |
The *initializer* shall be of the form “`=` *assignment-expression*”, of
|
| 172 |
the form “`{` *assignment-expression* `}`”, or of the form “`(`
|
| 173 |
*assignment-expression* `)`”, where the *assignment-expression* is of
|
| 174 |
array or non-union class type.
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
If the *decl-specifier-seq* contains the `typedef` specifier, the
|
| 177 |
+
declaration is a *typedef declaration* and each *declarator-id* is
|
| 178 |
+
declared to be a *typedef-name*, synonymous with its associated type
|
| 179 |
+
[[dcl.typedef]].
|
| 180 |
+
|
| 181 |
+
[*Note 4*: Such a *declarator-id* is an *identifier*
|
| 182 |
+
[[class.conv.fct]]. — *end note*]
|
| 183 |
+
|
| 184 |
+
Otherwise, if the type associated with a *declarator-id* is a function
|
| 185 |
+
type [[dcl.fct]], the declaration is a *function declaration*.
|
| 186 |
+
Otherwise, if the type associated with a *declarator-id* is an object or
|
| 187 |
+
reference type, the declaration is an *object declaration*. Otherwise,
|
| 188 |
+
the program is ill-formed.
|
| 189 |
+
|
| 190 |
+
[*Example 4*:
|
| 191 |
+
|
| 192 |
+
``` cpp
|
| 193 |
+
int f(), x; // OK, function declaration for f and object declaration for x
|
| 194 |
+
extern void g(), // OK, function declaration for g
|
| 195 |
+
y; // error: void is not an object type
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
— *end example*]
|
| 199 |
|
| 200 |
Syntactic components beyond those found in the general form of
|
| 201 |
+
*simple-declaration* are added to a function declaration to make a
|
| 202 |
*function-definition*. An object declaration, however, is also a
|
| 203 |
definition unless it contains the `extern` specifier and has no
|
| 204 |
initializer [[basic.def]]. An object definition causes storage of
|
| 205 |
appropriate size and alignment to be reserved and any appropriate
|
| 206 |
initialization [[dcl.init]] to be done.
|
| 207 |
|
| 208 |
A *nodeclspec-function-declaration* shall declare a constructor,
|
| 209 |
destructor, or conversion function.
|
| 210 |
|
| 211 |
+
[*Note 5*: Because a member function cannot be subject to a
|
| 212 |
+
non-defining declaration outside of a class definition [[class.mfct]], a
|
| 213 |
+
*nodeclspec-function-declaration* can only be used in a
|
| 214 |
*template-declaration* [[temp.pre]], *explicit-instantiation*
|
| 215 |
[[temp.explicit]], or *explicit-specialization*
|
| 216 |
[[temp.expl.spec]]. — *end note*]
|
| 217 |
|
| 218 |
+
In a *static_assert-declaration*, the *constant-expression* is
|
| 219 |
+
contextually converted to `bool` and the converted expression shall be a
|
| 220 |
+
constant expression [[expr.const]]. If the value of the expression when
|
| 221 |
+
so converted is `true` or the expression is evaluated in the context of
|
| 222 |
+
a template definition, the declaration has no effect. Otherwise, the
|
| 223 |
+
*static_assert-declaration* *fails*, the program is ill-formed, and the
|
| 224 |
+
resulting diagnostic message [[intro.compliance]] should include the
|
| 225 |
+
text of the *string-literal*, if one is supplied.
|
| 226 |
+
|
| 227 |
+
[*Example 5*:
|
| 228 |
+
|
| 229 |
+
``` cpp
|
| 230 |
+
static_assert(sizeof(int) == sizeof(void*), "wrong pointer size");
|
| 231 |
+
static_assert(sizeof(int[2])); // OK, narrowing allowed
|
| 232 |
+
|
| 233 |
+
template <class T>
|
| 234 |
+
void f(T t) {
|
| 235 |
+
if constexpr (sizeof(T) == sizeof(int)) {
|
| 236 |
+
use(t);
|
| 237 |
+
} else {
|
| 238 |
+
static_assert(false, "must be int-sized");
|
| 239 |
+
}
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
void g(char c) {
|
| 243 |
+
f(0); // OK
|
| 244 |
+
f(c); // error on implementations where sizeof(int) > 1: must be int-sized
|
| 245 |
+
}
|
| 246 |
+
```
|
| 247 |
+
|
| 248 |
+
— *end example*]
|
| 249 |
+
|
| 250 |
+
An *empty-declaration* has no effect.
|
| 251 |
+
|
| 252 |
+
Except where otherwise specified, the meaning of an
|
| 253 |
+
*attribute-declaration* is *implementation-defined*.
|
| 254 |
+
|