Files
2025-10-25 03:02:53 +03:00

196 lines
9.2 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[basic.scope.pdecl]
# 6 Basics [[basic]](./#basic)
## 6.4 Scope [[basic.scope]](basic.scope#pdecl)
### 6.4.2 Point of declaration [basic.scope.pdecl]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1237)
The [*locus*](#def:locus "6.4.2Point of declaration[basic.scope.pdecl]") of a declaration ([[basic.pre]](basic.pre "6.1Preamble")) that is a declarator
is immediately after the complete declarator ([[dcl.decl]](dcl.decl "9.3Declarators"))[.](#1.sentence-1)
[*Example [1](#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 x outside its lifetime ([[basic.life]](basic.life "6.8.4Lifetime"))[.](#1.sentence-2)
— *end example*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1251)
[*Note [1](#note-1)*:
A name from an outer scope remains visible up to
the locus of the declaration that hides it[.](#2.sentence-1)
[*Example [2](#example-2)*:
const int i = 2;{ int i[i]; } declares a block-scope array of two integers[.](#2.sentence-2)
— *end example*]
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1265)
The locus of a [*class-specifier*](class.pre#nt:class-specifier "11.1Preamble[class.pre]") is immediately after
the [*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]") or [*simple-template-id*](temp.names#nt:simple-template-id "13.3Names of template specializations[temp.names]") (if any)
in its [*class-head*](class.pre#nt:class-head "11.1Preamble[class.pre]") ([[class.pre]](class.pre "11.1Preamble"))[.](#3.sentence-1)
The locus of an [*enum-specifier*](dcl.enum#nt:enum-specifier "9.8.1Enumeration declarations[dcl.enum]") is immediately after
its [*enum-head*](dcl.enum#nt:enum-head "9.8.1Enumeration declarations[dcl.enum]");
the locus of an [*opaque-enum-declaration*](dcl.enum#nt:opaque-enum-declaration "9.8.1Enumeration declarations[dcl.enum]") is immediately after it ([[dcl.enum]](dcl.enum "9.8.1Enumeration declarations"))[.](#3.sentence-2)
The locus of an [*alias-declaration*](dcl.pre#nt:alias-declaration "9.1Preamble[dcl.pre]") is immediately after it[.](#3.sentence-3)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1277)
The locus of a [*using-declarator*](namespace.udecl#nt:using-declarator "9.10The using declaration[namespace.udecl]") that does not name a constructor
is immediately after the [*using-declarator*](namespace.udecl#nt:using-declarator "9.10The using declaration[namespace.udecl]") ([[namespace.udecl]](namespace.udecl "9.10The using declaration"))[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1282)
The locus of an [*enumerator-definition*](dcl.enum#nt:enumerator-definition "9.8.1Enumeration declarations[dcl.enum]") is immediately after it[.](#5.sentence-1)
[*Example [3](#example-3)*: const int x = 12;{ enum { x = x }; }
Here, the enumerator x is initialized with the value of the
constant x, namely 12[.](#5.sentence-2)
— *end example*]
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1293)
[*Note [2](#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[.](#6.sentence-1)
[*Example [4](#example-4)*: struct X {enum E { z = 16 }; int b[X::z]; // OK}; — *end example*]
— *end note*]
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1309)
The locus of an [*elaborated-type-specifier*](dcl.type.elab#nt:elaborated-type-specifier "9.2.9.5Elaborated type specifiers[dcl.type.elab]") that is a declaration ([[dcl.type.elab]](dcl.type.elab "9.2.9.5Elaborated type specifiers")) is immediately after it[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1313)
The locus of an injected-class-name declaration ([[class.pre]](class.pre "11.1Preamble"))
is immediately following the opening brace of the class definition[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1317)
The locus of the implicit declaration of
a function-local predefined variable ([[dcl.fct.def.general]](dcl.fct.def.general "9.6.1General"))
is immediately before
the [*function-body*](dcl.fct.def.general#nt:function-body "9.6.1General[dcl.fct.def.general]") of its function's definition[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1323)
The locus of the declaration of a structured binding ([[dcl.struct.bind]](dcl.struct.bind "9.7Structured binding declarations"))
is immediately after
the [*identifier-list*](cpp.pre#nt:identifier-list "15.1Preamble[cpp.pre]") of the structured binding declaration[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1328)
The locus of a [*for-range-declaration*](stmt.pre#nt:for-range-declaration "8.1Preamble[stmt.pre]") of a range-based for statement ([[stmt.ranged]](stmt.ranged "8.6.5The range-based for statement"))
is immediately after the [*for-range-initializer*](stmt.pre#nt:for-range-initializer "8.1Preamble[stmt.pre]")[.](#11.sentence-1)
The locus of a [*for-range-declaration*](stmt.pre#nt:for-range-declaration "8.1Preamble[stmt.pre]") of an expansion statement ([[stmt.expand]](stmt.expand "8.7Expansion statements"))
is immediately after the [*expansion-initializer*](stmt.expand#nt:expansion-initializer "8.7Expansion statements[stmt.expand]")[.](#11.sentence-2)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1336)
The locus of a [*template-parameter*](temp.param#nt:template-parameter "13.2Template parameters[temp.param]") is immediately after it[.](#12.sentence-1)
[*Example [5](#example-5)*: typedef unsigned char T;template<class T = T // lookup finds the [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4The typedef specifier[dcl.typedef]") , T // lookup finds the template parameter N = 0> struct A { }; — *end example*]
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1348)
The locus of a [*result-name-introducer*](dcl.contract.res#nt:result-name-introducer "9.4.2Referring to the result object[dcl.contract.res]") ([[dcl.contract.res]](dcl.contract.res "9.4.2Referring to the result object"))
is immediately after it[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1352)
The locus of a [*concept-definition*](temp.concept#nt:concept-definition "13.7.9Concept definitions[temp.concept]") is immediately after its [*concept-name*](temp.concept#nt:concept-name "13.7.9Concept definitions[temp.concept]") ([[temp.concept]](temp.concept "13.7.9Concept definitions"))[.](#14.sentence-1)
[*Note [3](#note-3)*:
The [*constraint-expression*](temp.constr.decl#nt:constraint-expression "13.5.3Constrained declarations[temp.constr.decl]") cannot use
the [*concept-name*](temp.concept#nt:concept-name "13.7.9Concept definitions[temp.concept]")[.](#14.sentence-2)
— *end note*]
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1360)
The locus of a [*namespace-definition*](namespace.def.general#nt:namespace-definition "9.9.2.1General[namespace.def.general]") with an [*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]") is immediately after the [*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]")[.](#15.sentence-1)
[*Note [4](#note-4)*:
An identifier is invented
for an [*unnamed-namespace-definition*](namespace.def.general#nt:unnamed-namespace-definition "9.9.2.1General[namespace.def.general]") ([[namespace.unnamed]](namespace.unnamed "9.9.2.2Unnamed namespaces"))[.](#15.sentence-2)
— *end note*]
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1369)
[*Note [5](#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]](class.friend "11.8.4Friends"))[.](#16.sentence-1)
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[.](#16.sentence-2)
— *end note*]
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1381)
[*Note [6](#note-6)*:
For point of instantiation of a template, see [[temp.point]](temp.point "13.8.4.1Point of instantiation")[.](#17.sentence-1)
— *end note*]