[basic.scope.pdecl] (original) (raw)
6 Basics [basic]
6.4.2 Point of declaration [basic.scope.pdecl]
The point of declaration for a name is immediately after its complete declarator ([dcl.decl]) and before itsinitializer (if any), except as noted below.
[Example 1: unsigned char x = 12;{ unsigned char x = x; }
Here, the initialization of the second x has undefined behavior, because the initializer accesses the second xoutside its lifetime ([basic.life]).
— _end example_]
[Note 1:
A name from an outer scope remains visible up to the point of declaration of the name that hides it.
[Example 2:
const int i = 2;{ int i[i]; } declares a block-scope array of two integers.
— _end example_]
— _end note_]
The point of declaration of an alias or alias template immediately follows the defining-type-id to which the alias refers.
The point of declaration for an enumerator is immediately after itsenumerator-definition.
[Example 3: const int x = 12;{ enum { x = x }; }
Here, the enumerator x is initialized with the value of the constant x, namely 12.
— _end example_]
After the point of declaration of a class member, the member name can be looked up in the scope of its class.
[Note 2:
This is true even if the class is an incomplete class.
For example,struct X { enum E { z = 16 };int b[X::z]; };
— _end note_]
The point of declaration for an injected-class-name ([class.pre]) is immediately following the opening brace of the class definition.
The point of declaration for a template parameter is immediately after its completetemplate-parameter.
[Example 4: typedef unsigned char T;template<class T= T , T N = 0> struct A { }; — _end example_]
[Note 5:
Friend declarations refer to functions or classes that are members of the nearest enclosing namespace, but they do not introduce new names into that namespace ([namespace.memdef]).
Function declarations at block scope and variable declarations with theextern specifier at block scope refer to declarations that are members of an enclosing namespace, but they do not introduce new names into that scope.
— _end note_]
[Note 6:
For point of instantiation of a template, see [temp.point].
— _end note_]