Annex A (informative)
Grammar summary
[gram]
A.7
Declarations
[gram.dcl]
declaration-seq
:
declaration
declaration-seq
declaration
declaration
:
name-declaration
special-declaration
name-declaration
:
block-declaration
nodeclspec-function-declaration
function-definition
template-declaration
deduction-guide
linkage-specification
namespace-definition
empty-declaration
attribute-declaration
module-import-declaration
special-declaration
:
explicit-instantiation
explicit-specialization
export-declaration
block-declaration
:
simple-declaration
asm-declaration
namespace-alias-definition
using-declaration
using-enum-declaration
using-directive
static_assert-declaration
alias-declaration
opaque-enum-declaration
nodeclspec-function-declaration
:
attribute-specifier-seq
o
p
t
declarator
;
alias-declaration
:
using
identifier
attribute-specifier-seq
o
p
t
=
defining-type-id
;
simple-declaration
:
decl-specifier-seq
init-declarator-list
o
p
t
;
attribute-specifier-seq
decl-specifier-seq
init-declarator-list
;
attribute-specifier-seq
o
p
t
decl-specifier-seq
ref-qualifier
o
p
t
[
identifier-list
]
initializer
;
static_assert-declaration
:
static_
assert
(
constant-expression
)
;
static_
assert
(
constant-expression
,
string-literal
)
;
empty-declaration
:
;
attribute-declaration
:
attribute-specifier-seq
;
decl-specifier
:
storage-class-specifier
defining-type-specifier
function-specifier
friend
typedef
constexpr
consteval
constinit
inline
decl-specifier-seq
:
decl-specifier
attribute-specifier-seq
o
p
t
decl-specifier
decl-specifier-seq
storage-class-specifier
:
static
thread_
local
extern
mutable
function-specifier
:
virtual
explicit-specifier
explicit-specifier
:
explicit
(
constant-expression
)
explicit
typedef-name
:
identifier
simple-template-id
type-specifier
:
simple-type-specifier
elaborated-type-specifier
typename-specifier
cv-qualifier
type-specifier-seq
:
type-specifier
attribute-specifier-seq
o
p
t
type-specifier
type-specifier-seq
defining-type-specifier
:
type-specifier
class-specifier
enum-specifier
defining-type-specifier-seq
:
defining-type-specifier
attribute-specifier-seq
o
p
t
defining-type-specifier
defining-type-specifier-seq
simple-type-specifier
:
nested-name-specifier
o
p
t
type-name
nested-name-specifier
template
simple-template-id
decltype-specifier
placeholder-type-specifier
nested-name-specifier
o
p
t
template-name
char
char8_
t
char16_
t
char32_
t
wchar_
t
bool
short
int
long
signed
unsigned
float
double
void
type-name
:
class-name
enum-name
typedef-name
elaborated-type-specifier
:
class-key
attribute-specifier-seq
o
p
t
nested-name-specifier
o
p
t
identifier
class-key
simple-template-id
class-key
nested-name-specifier
template
o
p
t
simple-template-id
enum
nested-name-specifier
o
p
t
identifier
decltype-specifier
:
decltype
(
expression
)
placeholder-type-specifier
:
type-constraint
o
p
t
auto
type-constraint
o
p
t
decltype
(
auto
)
init-declarator-list
:
init-declarator
init-declarator-list
,
init-declarator
init-declarator
:
declarator
initializer
o
p
t
declarator
requires-clause
declarator
:
ptr-declarator
noptr-declarator
parameters-and-qualifiers
trailing-return-type
ptr-declarator
:
noptr-declarator
ptr-operator
ptr-declarator
noptr-declarator
:
declarator-id
attribute-specifier-seq
o
p
t
noptr-declarator
parameters-and-qualifiers
noptr-declarator
[
constant-expression
o
p
t
]
attribute-specifier-seq
o
p
t
(
ptr-declarator
)
parameters-and-qualifiers
:
(
parameter-declaration-clause
)
cv-qualifier-seq
o
p
t
ref-qualifier
o
p
t
noexcept-specifier
o
p
t
attribute-specifier-seq
o
p
t
trailing-return-type
:
-
>
type-id
ptr-operator
:
*
attribute-specifier-seq
o
p
t
cv-qualifier-seq
o
p
t
&
attribute-specifier-seq
o
p
t
&
&
attribute-specifier-seq
o
p
t
nested-name-specifier
*
attribute-specifier-seq
o
p
t
cv-qualifier-seq
o
p
t
cv-qualifier-seq
:
cv-qualifier
cv-qualifier-seq
o
p
t
cv-qualifier
:
const
volatile
ref-qualifier
:
&
&
&
declarator-id
:
.
.
.
o
p
t
id-expression
type-id
:
type-specifier-seq
abstract-declarator
o
p
t
defining-type-id
:
defining-type-specifier-seq
abstract-declarator
o
p
t
abstract-declarator
:
ptr-abstract-declarator
noptr-abstract-declarator
o
p
t
parameters-and-qualifiers
trailing-return-type
abstract-pack-declarator
ptr-abstract-declarator
:
noptr-abstract-declarator
ptr-operator
ptr-abstract-declarator
o
p
t
noptr-abstract-declarator
:
noptr-abstract-declarator
o
p
t
parameters-and-qualifiers
noptr-abstract-declarator
o
p
t
[
constant-expression
o
p
t
]
attribute-specifier-seq
o
p
t
(
ptr-abstract-declarator
)
abstract-pack-declarator
:
noptr-abstract-pack-declarator
ptr-operator
abstract-pack-declarator
noptr-abstract-pack-declarator
:
noptr-abstract-pack-declarator
parameters-and-qualifiers
noptr-abstract-pack-declarator
[
constant-expression
o
p
t
]
attribute-specifier-seq
o
p
t
.
.
.
parameter-declaration-clause
:
parameter-declaration-list
o
p
t
.
.
.
o
p
t
parameter-declaration-list
,
.
.
.
parameter-declaration-list
:
parameter-declaration
parameter-declaration-list
,
parameter-declaration
parameter-declaration
:
attribute-specifier-seq
o
p
t
this
o
p
t
decl-specifier-seq
declarator
attribute-specifier-seq
o
p
t
decl-specifier-seq
declarator
=
initializer-clause
attribute-specifier-seq
o
p
t
this
o
p
t
decl-specifier-seq
abstract-declarator
o
p
t
attribute-specifier-seq
o
p
t
decl-specifier-seq
abstract-declarator
o
p
t
=
initializer-clause
initializer
:
brace-or-equal-initializer
(
expression-list
)
brace-or-equal-initializer
:
=
initializer-clause
braced-init-list
initializer-clause
:
assignment-expression
braced-init-list
braced-init-list
:
{
initializer-list
,
o
p
t
}
{
designated-initializer-list
,
o
p
t
}
{
}
initializer-list
:
initializer-clause
.
.
.
o
p
t
initializer-list
,
initializer-clause
.
.
.
o
p
t
designated-initializer-list
:
designated-initializer-clause
designated-initializer-list
,
designated-initializer-clause
designated-initializer-clause
:
designator
brace-or-equal-initializer
designator
:
.
identifier
expr-or-braced-init-list
:
expression
braced-init-list
function-definition
:
attribute-specifier-seq
o
p
t
decl-specifier-seq
o
p
t
declarator
virt-specifier-seq
o
p
t
function-body
attribute-specifier-seq
o
p
t
decl-specifier-seq
o
p
t
declarator
requires-clause
function-body
function-body
:
ctor-initializer
o
p
t
compound-statement
function-try-block
=
default
;
=
delete
;
enum-name
:
identifier
enum-specifier
:
enum-head
{
enumerator-list
o
p
t
}
enum-head
{
enumerator-list
,
}
enum-head
:
enum-key
attribute-specifier-seq
o
p
t
enum-head-name
o
p
t
enum-base
o
p
t
enum-head-name
:
nested-name-specifier
o
p
t
identifier
opaque-enum-declaration
:
enum-key
attribute-specifier-seq
o
p
t
enum-head-name
enum-base
o
p
t
;
enum-key
:
enum
enum
class
enum
struct
enum-base
:
:
type-specifier-seq
enumerator-list
:
enumerator-definition
enumerator-list
,
enumerator-definition
enumerator-definition
:
enumerator
enumerator
=
constant-expression
enumerator
:
identifier
attribute-specifier-seq
o
p
t
using-enum-declaration
:
using
enum
using-enum-declarator
;
using-enum-declarator
:
nested-name-specifier
o
p
t
identifier
nested-name-specifier
o
p
t
simple-template-id
namespace-name
:
identifier
namespace-alias
namespace-definition
:
named-namespace-definition
unnamed-namespace-definition
nested-namespace-definition
named-namespace-definition
:
inline
o
p
t
namespace
attribute-specifier-seq
o
p
t
identifier
{
namespace-body
}
unnamed-namespace-definition
:
inline
o
p
t
namespace
attribute-specifier-seq
o
p
t
{
namespace-body
}
nested-namespace-definition
:
namespace
enclosing-namespace-specifier
::
inline
o
p
t
identifier
{
namespace-body
}
enclosing-namespace-specifier
:
identifier
enclosing-namespace-specifier
::
inline
o
p
t
identifier
namespace-body
:
declaration-seq
o
p
t
namespace-alias
:
identifier
namespace-alias-definition
:
namespace
identifier
=
qualified-namespace-specifier
;
qualified-namespace-specifier
:
nested-name-specifier
o
p
t
namespace-name
using-directive
:
attribute-specifier-seq
o
p
t
using
namespace
nested-name-specifier
o
p
t
namespace-name
;
using-declaration
:
using
using-declarator-list
;
using-declarator-list
:
using-declarator
.
.
.
o
p
t
using-declarator-list
,
using-declarator
.
.
.
o
p
t
using-declarator
:
typename
o
p
t
nested-name-specifier
unqualified-id
asm-declaration
:
attribute-specifier-seq
o
p
t
asm
(
string-literal
)
;
linkage-specification
:
extern
string-literal
{
declaration-seq
o
p
t
}
extern
string-literal
name-declaration
attribute-specifier-seq
:
attribute-specifier-seq
o
p
t
attribute-specifier
attribute-specifier
:
[
[
attribute-using-prefix
o
p
t
attribute-list
]
]
alignment-specifier
alignment-specifier
:
alignas
(
type-id
.
.
.
o
p
t
)
alignas
(
constant-expression
.
.
.
o
p
t
)
attribute-using-prefix
:
using
attribute-namespace
:
attribute-list
:
attribute
o
p
t
attribute-list
,
attribute
o
p
t
attribute
.
.
.
attribute-list
,
attribute
.
.
.
attribute
:
attribute-token
attribute-argument-clause
o
p
t
attribute-token
:
identifier
attribute-scoped-token
attribute-scoped-token
:
attribute-namespace
::
identifier
attribute-namespace
:
identifier
attribute-argument-clause
:
(
balanced-token-seq
o
p
t
)
balanced-token-seq
:
balanced-token
balanced-token-seq
balanced-token
balanced-token
:
(
balanced-token-seq
o
p
t
)
[
balanced-token-seq
o
p
t
]
{
balanced-token-seq
o
p
t
}
any
token
other than a parenthesis, a bracket, or a brace