Стандарт C++ 11 (1119564), страница 55
Текст из файла (страница 55)
[ Note:If two consecutive left square brackets appear where an attribute-specifier is not allowed, the program is illformed even if the brackets match an alternative grammar production. — end note ] [ Example:int p[10];void f() {int x = 42, y[5];int(p[[x] { return x; }()]);y[[] { return 2; }()] = 2;//////////error: malformed attribute on a nesteddeclarator-id and not a function-style cast ofan element of p.error even though attributes are not allowedin this context.}— end example ]7.6.2Alignment specifier[dcl.align]1An alignment-specifier may be applied to a variable or to a class data member, but it shall not be appliedto a bit-field, a function parameter, the formal parameter of a catch clause (15.3), or a variable declaredwith the register storage class specifier.
An alignment-specifier may also be applied to the declaration ofa class or enumeration type. An alignment-specifier with an ellipsis is a pack expansion (14.5.3).2When the alignment-specifier is of the form alignas( assignment-expression ):— the assignment-expression shall be an integral constant expression— if the constant expression evaluates to a fundamental alignment, the alignment requirement of thedeclared entity shall be the specified fundamental alignment— if the constant expression evaluates to an extended alignment and the implementation supports thatalignment in the context of the declaration, the alignment of the declared entity shall be that alignment— if the constant expression evaluates to an extended alignment and the implementation does not supportthat alignment in the context of the declaration, the program is ill-formed— if the constant expression evaluates to zero, the alignment specifier shall have no effect— otherwise, the program is ill-formed.3When the alignment-specifier is of the form alignas( type-id ), it shall have the same effect as alignas(alignof(type-id )) (5.3.6).4When multiple alignment-specifiers are specified for an entity, the alignment requirement shall be set to thestrictest specified alignment.§ 7.6.2178© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)5The combined effect of all alignment-specifiers in a declaration shall not specify an alignment that is lessstrict than the alignment that would be required for the entity being declared if all alignment-specifiers wereomitted (including those in other declarations).6If the defining declaration of an entity has an alignment-specifier, any non-defining declaration of thatentity shall either specify equivalent alignment or have no alignment-specifier.
Conversely, if any declarationof an entity has an alignment-specifier, every defining declaration of that entity shall specify an equivalentalignment. No diagnostic is required if declarations of an entity have different alignment-specifiers in differenttranslation units.[ Example:// Translation unit #1:struct S { int x; } s, p = &s;// Translation unit #2:struct alignas(16) S;extern S* p;// error: definition of S lacks alignment; no// diagnostic required— end example ]7[ Example: An aligned buffer with an alignment requirement of A and holding N elements of type T otherthan char, signed char, or unsigned char can be declared as:alignas(T) alignas(A) T buffer[N];Specifying alignas(T) ensures that the final requested alignment will not be weaker than alignof(T), andtherefore the program will not be ill-formed.
— end example ]8[ Example:alignas(double) void f();alignas(double) unsigned char c[sizeof(double)];extern unsigned char c[sizeof(double)];alignas(float)extern unsigned char c[sizeof(double)];// error: alignment applied to function// array of characters, suitably aligned for a double// no alignas necessary// error: different alignment in declaration— end example ]7.6.3Noreturn attribute[dcl.attr.noreturn]1The attribute-token noreturn specifies that a function does not return. It shall appear at most once ineach attribute-list and no attribute-argument-clause shall be present.
The attribute may be applied tothe declarator-id in a function declaration. The first declaration of a function shall specify the noreturnattribute if any declaration of that function specifies the noreturn attribute. If a function is declared withthe noreturn attribute in one translation unit and the same function is declared without the noreturnattribute in another translation unit, the program is ill-formed; no diagnostic required.2If a function f is called where f was previously declared with the noreturn attribute and f eventuallyreturns, the behavior is undefined.
[ Note: The function may terminate by throwing an exception. — endnote ] [ Note: Implementations are encouraged to issue a warning if a function marked [[noreturn]] mightreturn. — end note ]3[ Example:§ 7.6.3© ISO/IEC 2011 – All rights reserved179ISO/IEC 14882:2011(E)[[ noreturn ]] void f() {throw "error";// OK}[[ noreturn ]] void q(int i) { // behavior is undefined if called with an argument <= 0if (i > 0)throw "positive";}— end example ]7.6.4Carries dependency attribute[dcl.attr.depend]1The attribute-token carries_dependency specifies dependency propagation into and out of functions.
Itshall appear at most once in each attribute-list and no attribute-argument-clause shall be present. Theattribute may be applied to the declarator-id of a parameter-declaration in a function declaration or lambda,in which case it specifies that the initialization of the parameter carries a dependency to (1.10) each lvalueto-rvalue conversion (4.1) of that object. The attribute may also be applied to the declarator-id of a functiondeclaration, in which case it specifies that the return value, if any, carries a dependency to the evaluation ofthe function call expression.2The first declaration of a function shall specify the carries_dependency attribute for its declarator-id if anydeclaration of the function specifies the carries_dependency attribute.
Furthermore, the first declaration ofa function shall specify the carries_dependency attribute for a parameter if any declaration of that functionspecifies the carries_dependency attribute for that parameter. If a function or one of its parameters isdeclared with the carries_dependency attribute in its first declaration in one translation unit and thesame function or one of its parameters is declared without the carries_dependency attribute in its firstdeclaration in another translation unit, the program is ill-formed; no diagnostic required.3[ Note: The carries_dependency attribute does not change the meaning of the program, but may result ingeneration of more efficient code. — end note ]4[ Example:/∗ Translation unit A. ∗/struct foo { int* a; int* b; };std::atomic<struct foo *> foo_head[10];int foo_array[10][10];[[carries_dependency]] struct foo* f(int i) {return foo_head[i].load(memory_order_consume);}[[carries_dependency]] int g(int* x, int* y) {return kill_dependency(foo_array[*x][*y]);}/∗ Translation unit B.
∗/[[carries_dependency]] struct foo* f(int i);[[carries_dependency]] int* g(int* x, int* y);int c = 3;void h(int i) {§ 7.6.4180© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)struct foo* p;p = f(i);do_something_with(g(&c, p->a));do_something_with(g(p->a, &c));}5The carries_dependency attribute on function f means that the return value carries a dependency out off, so that the implementation need not constrain ordering upon return from f. Implementations of f andits caller may choose to preserve dependencies instead of emitting hardware memory ordering instructions(a.k.a. fences).6Function g’s second argument has a carries_dependency attribute, but its first argument does not. Therefore, function h’s first call to g carries a dependency into g, but its second call does not. The implementationmight need to insert a fence prior to the second call to g.— end example ]§ 7.6.4© ISO/IEC 2011 – All rights reserved181ISO/IEC 14882:2011(E)81Declarators[dcl.decl]A declarator declares a single variable, function, or type, within a declaration.
The init-declarator-listappearing in a declaration is a comma-separated sequence of declarators, each of which can have an initializer.init-declarator-list:init-declaratorinit-declarator-list , init-declaratorinit-declarator:declarator initializeropt2The three components of a simple-declaration are the attributes (7.6), the specifiers (decl-specifier-seq; 7.1)and the declarators (init-declarator-list).
The specifiers indicate the type, storage class or other propertiesof the entities being declared. The declarators specify the names of these entities and (optionally) modifythe type of the specifiers with operators such as * (pointer to) and () (function returning). Initial valuescan also be specified in a declarator; initializers are discussed in 8.5 and 12.6.3Each init-declarator in a declaration is analyzed separately as if it was in a declaration by itself.974Declarators have the syntaxdeclarator:ptr-declaratornoptr-declarator parameters-and-qualifiers trailing-return-typeptr-declarator:noptr-declaratorptr-operator ptr-declaratornoptr-declarator:declarator-id attribute-specifier-seqoptnoptr-declarator parameters-and-qualifiersnoptr-declarator [ constant-expressionopt ] attribute-specifier-seqopt( ptr-declarator )97) A declaration with several declarators is usually equivalent to the corresponding sequence of declarations each with a singledeclarator.