Declarations[Decl]

9 Declarations[Decl]

9.1 Preamble[Decl.Pre]

Declarations generally specify how names are to be interpreted. Declarations have the form

declaration-seq:
declaration
declaration-seq declaration
declaration:
name-declaration
special-declaration
name-declaration:
block-declaration
function-definition
template-declaration
namespace-definition
empty-declaration
attribute-declaration
cbuffer-declaration
special-declaration:
export-declaration-group
cbuffer-member-declaration
block-declaration:
simple-declaration
namespace-alias-definition
using-declaration
using-directive
static_assert-declaration
alias-declaration
opaque-enum-declaration
empty-declaration:
;

9.2 Specifiers[Decl.Spec]

9.2.1 General[Decl.Spec.General]

The specifiers that can be used in a declaration are

decl-specifier:
storage-class-specifier
type-specifier
function-specifier
typedef
decl-specifier-seq:
decl-specifier
decl-specifier decl-specifier-seq

9.2.2 Function specifiers[Decl.Spec.Fct]

A function-specifier can be used only in a function declaration.

function-specifier:
export

The export specifier denotes that the function has program linkage (6.7.1).

The export specifier cannot be used on functions directly or indirectly within an unnamed namespace.

Functions with program linkage can also be specified in export-declaration-group ([Decl.Export]).

If a function is declared with an export specifier then all redeclarations of the same function must also use the export specifier or be part of export-declaration-group ([Decl.Export]).

9.3 Declarators[Decl.Decl]

9.4 Initializers[Decl.Init]

The process of initialization described in this section applies to all initializers regardless of the context.

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 ,opt }
{ }
initializer-list:
initializer-clause
initializer-list , initializer-clause

9.4.1 Aggregate Initialization[Decl.Init.Agg]

An aggregate is a vector, matrix, array, or class.

The subobjects of an aggregate have a defined order. For vectors and arrays the order is increasing subscript order. For matrices it is increasing subscript order with the subscript nesting such that in the notation Mat[M][N], the ordering is Mat[0][0]...Mat[0][N]...Mat[M][0]...Mat[M][N]. For classes the order is base class, followed by member subobjects in declaration order.

A flattened ordering of subobjects can be produced by performing a depth-first traversal of the subobjects of an object following the defined subobject ordering.

Each braced initializer list is comprised of zero or more initializer-clause expressions, which is either another braced initializer list or an expression which generates a value that either is or can be implicitly converted to an rvalue. Each assignment-expression is an object, which may be a scalar or aggregate type. A flattened initializer sequence is a sequence of expressions constructed by a depth-first traversal over each assignment-expression in an initializer-list and performing a depth-first traversal accessing each subobject of the assignment-expression.

If the target object is an array of unknown size, the object is assumed to have m possible elements during parsing, where m > 0.

An initializer-list is a valid initializer if for each element En mod  m in the target object’s flattened ordering there is a corresponding expression En in the flattened initializer sequence, which can be implicitly converted to the element’s type. For arrays of unknown size, the total number of expressions in the flattened initializer sequence must be a multiple of the array’s base element type.

An initializer-list is invalid if the flattened initializer sequence contains more or fewer elements than the target object’s flattened ordering, or if any initializer In cannot be implicitly converted to the corresponding element En’s type.