[basic.scope.pdecl] (original) (raw)

6 Basics [basic]

6.4.2 Point of declaration [basic.scope.pdecl]

The locus of a declaration ([basic.pre]) that is a declarator is immediately after the complete declarator ([dcl.decl]).

[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 locus of the declaration that hides it.

[Example 2:

const int i = 2;{ int i[i]; } declares a block-scope array of two integers.

— _end example_]

— _end note_]

[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_]

[Note 2:

After the declaration of a class member, the member name can be found in the scope of its class even if the class is an incomplete class.

[Example 4: struct X { enum E { z = 16 };int b[X::z]; }; — _end example_]

— _end note_]

The locus of an injected-class-name declaration ([class.pre]) is immediately following the opening brace of the class definition.

[Example 5: typedef unsigned char T;template<class T= T , T N = 0> struct A { }; — _end example_]

[Note 5:

Friend declarations can introduce functions or classes that belong to the nearest enclosing namespace or block scope, but they do not bind names anywhere ([class.friend]).

Function declarations at block scope and variable declarations with the extern specifier at block scope declare entities that belong to the nearest enclosing namespace, but they do not bind names in it.

— _end note_]

[Note 6:

For point of instantiation of a template, see [temp.point].

— _end note_]