Стандарт C++ 11 (1119564), страница 47
Текст из файла (страница 47)
It specifies that the named variable has automatic storage duration (3.7.3). A variabledeclared without a storage-class-specifier at block scope or declared as a function parameter has automaticstorage duration by default.3A register specifier is a hint to the implementation that the variable so declared will be heavily used.[ Note: The hint can be ignored and in most implementations it will be ignored if the address of the variableis taken. This use is deprecated (see D.2).
— end note ]4The thread_local specifier indicates that the named entity has thread storage duration (3.7.2). It shall beapplied only to the names of variables of namespace or block scope and to the names of static data members.When thread_local is applied to a variable of block scope the storage-class-specifier static is implied ifit does not appear explicitly.5The static specifier can be applied only to names of variables and functions and to anonymous unions (9.5).There can be no static function declarations within a block, nor any static function parameters. A staticspecifier used in the declaration of a variable declares the variable to have static storage duration (3.7.1),unless accompanied by the thread_local specifier, which declares the variable to have thread storageduration (3.7.2).
A static specifier can be used in declarations of class members; 9.4 describes its effect.For the linkage of a name declared with a static specifier, see 3.5.6The extern specifier can be applied only to the names of variables and functions. The extern specifier cannotbe used in the declaration of class members or function parameters. For the linkage of a name declared withan extern specifier, see 3.5. [ Note: The extern keyword can also be used in explicit-instantiations andlinkage-specifications, but it is not a storage-class-specifier in such contexts.
— end note ]7A name declared in a namespace scope without a storage-class-specifier has external linkage unless it hasinternal linkage because of a previous declaration and provided it is not declared const. Objects declaredconst and not explicitly declared extern have internal linkage.8The linkages implied by successive declarations for a given entity shall agree. That is, within a given scope,each declaration declaring the same variable name or the same overloading of a function name shall implythe same linkage. Each function in a given set of overloaded functions can have a different linkage, however.[ Example:static char* f();char* f(){ /∗ ... ∗/ }// f() has internal linkage// f() still has internal linkagechar* g();static char* g(){ /∗ ... ∗/ }// g() has external linkage// error: inconsistent linkagevoid h();inline void h();// external linkageinline void l();§ 7.1.1© ISO/IEC 2011 – All rights reserved143ISO/IEC 14882:2011(E)void l();// external linkageinline void m();extern void m();// external linkagestatic void n();inline void n();// internal linkagestatic int a;int a;// a has internal linkage// error: two definitionsstatic int b;extern int b;// b has internal linkage// b still has internal linkageint c;static int c;// c has external linkage// error: inconsistent linkageextern int d;static int d;// d has external linkage// error: inconsistent linkage— end example ]9The name of a declared but undefined class can be used in an extern declaration.
Such a declaration canonly be used in ways that do not require a complete class type. [ Example:structexternexternexternS;S a;S f();void g(S);void h() {g(a);f();}// error: S is incomplete// error: S is incomplete— end example ]10The mutable specifier can be applied only to names of class data members (9.2) and cannot be applied tonames declared const or static, and cannot be applied to reference members. [ Example:class X {mutable const int* p;mutable int* const q;};// OK// ill-formed— end example ]11The mutable specifier on a class data member nullifies a const specifier applied to the containing class objectand permits modification of the mutable class member even though the rest of the object is const (7.1.6.1).7.1.21Function specifiers[dcl.fct.spec]Function-specifiers can be used only in function declarations.function-specifier:inlinevirtualexplicit§ 7.1.2144© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)2A function declaration (8.3.5, 9.3, 11.3) with an inline specifier declares an inline function.
The inlinespecifier indicates to the implementation that inline substitution of the function body at the point of callis to be preferred to the usual function call mechanism. An implementation is not required to perform thisinline substitution at the point of call; however, even if this inline substitution is omitted, the other rulesfor inline functions defined by 7.1.2 shall still be respected.3A function defined within a class definition is an inline function.
The inline specifier shall not appear ona block scope function declaration.90 If the inline specifier is used in a friend declaration, that declarationshall be a definition or the function shall have previously been declared inline.4An inline function shall be defined in every translation unit in which it is odr-used and shall have exactlythe same definition in every case (3.2). [ Note: A call to the inline function may be encountered before itsdefinition appears in the translation unit. — end note ] If the definition of a function appears in a translationunit before its first declaration as inline, the program is ill-formed.
If a function with external linkage isdeclared inline in one translation unit, it shall be declared inline in all translation units in which it appears;no diagnostic is required. An inline function with external linkage shall have the same address in alltranslation units. A static local variable in an extern inline function always refers to the same object.A string literal in the body of an extern inline function is the same object in different translation units.[ Note: A string literal appearing in a default argument is not in the body of an inline function merelybecause the expression is used in a function call from that inline function.
— end note ] A type definedwithin the body of an extern inline function is the same type in every translation unit.5The virtual specifier shall be used only in the initial declaration of a non-static class member function;see 10.3.6The explicit specifier shall be used only in the declaration of a constructor or conversion function withinits class definition; see 12.3.1 and 12.3.2.7.1.31The typedef specifier[dcl.typedef ]Declarations containing the decl-specifier typedef declare identifiers that can be used later for namingfundamental (3.9.1) or compound (3.9.2) types. The typedef specifier shall not be combined in a declspecifier-seq with any other kind of specifier except a type-specifier, and it shall not be used in the declspecifier-seq of a parameter-declaration (8.3.5) nor in the decl-specifier-seq of a function-definition (8.4).typedef-name:identifierA name declared with the typedef specifier becomes a typedef-name.
Within the scope of its declaration, atypedef-name is syntactically equivalent to a keyword and names the type associated with the identifier inthe way described in Clause 8. A typedef-name is thus a synonym for another type. A typedef-name doesnot introduce a new type the way a class declaration (9.1) or enum declaration does. [ Example: aftertypedef int MILES, *KLICKSP;the constructionsMILES distance;extern KLICKSP metricp;are all correct declarations; the type of distance is int and that of metricp is “pointer to int.” — endexample ]2A typedef-name can also be introduced by an alias-declaration. The identifier following the using keywordbecomes a typedef-name and the optional attribute-specifier-seq following the identifier appertains to that90) The inline keyword has no effect on the linkage of a function.§ 7.1.3© ISO/IEC 2011 – All rights reserved145ISO/IEC 14882:2011(E)typedef-name.
It has the same semantics as if it were introduced by the typedef specifier. In particular, itdoes not define a new type and it shall not appear in the type-id. [ Example:using handler_t = void (*)(int);extern handler_t ignore;extern void (*ignore)(int);using cell = pair<void*, cell*>;// redeclare ignore// ill-formed— end example ]3In a given non-class scope, a typedef specifier can be used to redefine the name of any type declared in thatscope to refer to the type to which it already refers.
[ Example:typedeftypedeftypedeftypedefstruct s { /∗ ... ∗/ } s;int I;int I;I I;— end example ]4In a given class scope, a typedef specifier can be used to redefine any class-name declared in that scopethat is not also a typedef-name to refer to the type to which it already refers. [ Example:struct S {typedef struct A { } A;typedef struct B B;typedef A A;};// OK// OK// error— end example ]5If a typedef specifier is used to redefine in a given scope an entity that can be referenced using an elaboratedtype-specifier, the entity can continue to be referenced by an elaborated-type-specifier or as an enumerationor class name in an enumeration or class definition respectively.
[ Example:struct S;typedef struct S S;int main() {struct S* p;}struct S { };// OK// OK— end example ]6In a given scope, a typedef specifier shall not be used to redefine the name of any type declared in thatscope to refer to a different type. [ Example:class complex { /∗ ... ∗/ };typedef int complex;// error: redefinition— end example ]7Similarly, in a given scope, a class or enumeration shall not be declared with the same name as a typedef-namethat is declared in that scope and refers to a type other than the class or enumeration itself. [ Example:typedef int complex;class complex { /* ...*/ };// error: redefinition§ 7.1.3146© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)— end example ]8[ Note: A typedef-name that names a class type, or a cv-qualified version thereof, is also a class-name (9.1).If a typedef-name is used to identify the subject of an elaborated-type-specifier (7.1.6.3), a class definition(Clause 9), a constructor declaration (12.1), or a destructor declaration (12.4), the program is ill-formed.— end note ] [ Example:struct S {S();~S();};typedef struct S T;S a = T();struct T * p;// OK// error— end example ]9If the typedef declaration defines an unnamed class (or enum), the first typedef-name declared by the declaration to be that class type (or enum type) is used to denote the class type (or enum type) for linkagepurposes only (3.5).
[ Example:typedef struct { } *ps, S;// S is the class name for linkage purposes— end example ]7.1.41[dcl.friend]The friend specifier is used to specify access to class members; see 11.3.7.1.51The friend specifierThe constexpr specifier[dcl.constexpr]The constexpr specifier shall be applied only to the definition of a variable, the declaration of a function orfunction template, or the declaration of a static data member of a literal type (3.9). If any declaration of afunction or function template has constexpr specifier, then all its declarations shall contain the constexprspecifier.