Init
This commit is contained in:
52
cppdraft/namespace/alias.md
Normal file
52
cppdraft/namespace/alias.md
Normal file
@@ -0,0 +1,52 @@
|
||||
[namespace.alias]
|
||||
|
||||
# 9 Declarations [[dcl]](./#dcl)
|
||||
|
||||
## 9.9 Namespaces [[basic.namespace]](basic.namespace#namespace.alias)
|
||||
|
||||
### 9.9.3 Namespace alias [namespace.alias]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8417)
|
||||
|
||||
A [*namespace-alias-definition*](#nt:namespace-alias-definition "9.9.3 Namespace alias [namespace.alias]") declares a [*namespace alias*](#def:alias,namespace "9.9.3 Namespace alias [namespace.alias]") according to the following grammar:
|
||||
|
||||
[namespace-alias:](#nt:namespace-alias "9.9.3 Namespace alias [namespace.alias]")
|
||||
[*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")
|
||||
|
||||
[namespace-alias-definition:](#nt:namespace-alias-definition "9.9.3 Namespace alias [namespace.alias]")
|
||||
namespace [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") = [*qualified-namespace-specifier*](#nt:qualified-namespace-specifier "9.9.3 Namespace alias [namespace.alias]") ;
|
||||
namespace [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") = [*splice-specifier*](basic.splice#nt:splice-specifier "6.6 Splice specifiers [basic.splice]") ;
|
||||
|
||||
[qualified-namespace-specifier:](#nt:qualified-namespace-specifier "9.9.3 Namespace alias [namespace.alias]")
|
||||
[*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]")opt [*namespace-name*](namespace.def.general#nt:namespace-name "9.9.2.1 General [namespace.def.general]")
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8436)
|
||||
|
||||
The [*splice-specifier*](basic.splice#nt:splice-specifier "6.6 Splice specifiers [basic.splice]") (if any)
|
||||
shall designate a namespace that is not the global namespace[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8440)
|
||||
|
||||
The [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") in a [*namespace-alias-definition*](#nt:namespace-alias-definition "9.9.3 Namespace alias [namespace.alias]") becomes a [*namespace-alias*](#nt:namespace-alias "9.9.3 Namespace alias [namespace.alias]")[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8444)
|
||||
|
||||
The underlying entity ([[basic.pre]](basic.pre "6.1 Preamble")) of the namespace alias is
|
||||
the namespace either
|
||||
denoted by the [*qualified-namespace-specifier*](#nt:qualified-namespace-specifier "9.9.3 Namespace alias [namespace.alias]") or
|
||||
designated by the [*splice-specifier*](basic.splice#nt:splice-specifier "6.6 Splice specifiers [basic.splice]")[.](#4.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
When looking up a [*namespace-name*](namespace.def.general#nt:namespace-name "9.9.2.1 General [namespace.def.general]") in a[*namespace-alias-definition*](#nt:namespace-alias-definition "9.9.3 Namespace alias [namespace.alias]"), only namespace names are
|
||||
considered, see [[basic.lookup.udir]](basic.lookup.udir "6.5.7 Using-directives and namespace aliases")[.](#4.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
201
cppdraft/namespace/constraints.md
Normal file
201
cppdraft/namespace/constraints.md
Normal file
@@ -0,0 +1,201 @@
|
||||
[namespace.constraints]
|
||||
|
||||
# 16 Library introduction [[library]](./#library)
|
||||
|
||||
## 16.4 Library-wide requirements [[requirements]](requirements#namespace.constraints)
|
||||
|
||||
### 16.4.5 Constraints on programs [[constraints]](constraints#namespace.constraints)
|
||||
|
||||
#### 16.4.5.2 Namespace use [namespace.constraints]
|
||||
|
||||
#### [16.4.5.2.1](#namespace.std) Namespace std [[namespace.std]](namespace.std)
|
||||
|
||||
[1](#namespace.std-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2991)
|
||||
|
||||
Unless otherwise specified,
|
||||
the behavior of a C++ program is undefined if it adds declarations or definitions to namespacestd or to a namespace within namespacestd[.](#namespace.std-1.sentence-1)
|
||||
|
||||
[2](#namespace.std-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2998)
|
||||
|
||||
Unless explicitly prohibited,
|
||||
a program may add a template specialization for
|
||||
any standard library class template
|
||||
to namespacestd provided that
|
||||
|
||||
- [(2.1)](#namespace.std-2.1)
|
||||
|
||||
the added declaration
|
||||
depends on at least one program-defined type, and
|
||||
|
||||
- [(2.2)](#namespace.std-2.2)
|
||||
|
||||
the specialization meets the standard library requirements
|
||||
for the original template[.](#namespace.std-2.sentence-1)[151](#footnote-151 "Any library code that instantiates other library templates must be prepared to work adequately with any user-supplied specialization that meets the minimum requirements of this document.")
|
||||
|
||||
[3](#namespace.std-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3018)
|
||||
|
||||
The behavior of a C++ program is undefined
|
||||
if it declares an explicit or partial specialization
|
||||
of any standard library variable template,
|
||||
except where explicitly permitted by the specification of that variable template[.](#namespace.std-3.sentence-1)
|
||||
|
||||
[*Note [1](#namespace.std-note-1)*:
|
||||
|
||||
The requirements on an explicit or partial specialization
|
||||
are stated by each variable template that grants such permission[.](#namespace.std-3.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#namespace.std-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3028)
|
||||
|
||||
The behavior of a C++ program is undefined if it declares
|
||||
|
||||
- [(4.1)](#namespace.std-4.1)
|
||||
|
||||
an explicit specialization of any member function of a standard
|
||||
library class template, or
|
||||
|
||||
- [(4.2)](#namespace.std-4.2)
|
||||
|
||||
an explicit specialization of any member function template of a
|
||||
standard library class or class template, or
|
||||
|
||||
- [(4.3)](#namespace.std-4.3)
|
||||
|
||||
an explicit or partial specialization of any member class template
|
||||
of a standard library class or class template, or
|
||||
|
||||
- [(4.4)](#namespace.std-4.4)
|
||||
|
||||
a deduction guide for any standard library class template[.](#namespace.std-4.sentence-1)
|
||||
|
||||
[5](#namespace.std-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3043)
|
||||
|
||||
A program may explicitly instantiate
|
||||
a class template defined in the standard library
|
||||
only if the declaration
|
||||
|
||||
- [(5.1)](#namespace.std-5.1)
|
||||
|
||||
depends on the name of at least one program-defined type, and
|
||||
|
||||
- [(5.2)](#namespace.std-5.2)
|
||||
|
||||
the instantiation meets the standard library requirements for the
|
||||
original template[.](#namespace.std-5.sentence-1)
|
||||
|
||||
[6](#namespace.std-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3054)
|
||||
|
||||
Let *F* denote
|
||||
a standard library function ([[global.functions]](global.functions "16.4.6.4 Non-member functions")),
|
||||
a standard library static member function,
|
||||
or an instantiation
|
||||
of a standard library function template[.](#namespace.std-6.sentence-1)
|
||||
|
||||
Unless *F* is designated
|
||||
an [*addressable function*](#def:function,addressable "16.4.5.2.1 Namespace std [namespace.std]"),
|
||||
the behavior of a C++ program is unspecified (possibly ill-formed)
|
||||
if it explicitly or implicitly attempts
|
||||
to form a pointer
|
||||
to *F*[.](#namespace.std-6.sentence-2)
|
||||
|
||||
[*Note [2](#namespace.std-note-2)*:
|
||||
|
||||
Possible means of forming such pointers include
|
||||
application of the unary & operator ([[expr.unary.op]](expr.unary.op "7.6.2.2 Unary operators")),addressof ([[specialized.addressof]](specialized.addressof "20.2.11 addressof")),
|
||||
or
|
||||
a function-to-pointer standard conversion ([[conv.func]](conv.func "7.3.4 Function-to-pointer conversion"))[.](#namespace.std-6.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
Moreover,
|
||||
the behavior of a C++ program is unspecified (possibly ill-formed)
|
||||
if it attempts to form a reference
|
||||
to *F* or
|
||||
if it attempts to form a pointer-to-member designating
|
||||
either a standard library non-static member function ([[member.functions]](member.functions "16.4.6.5 Member functions"))
|
||||
or an instantiation of a standard library member function template[.](#namespace.std-6.sentence-4)
|
||||
|
||||
[7](#namespace.std-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3082)
|
||||
|
||||
Let *F* denote
|
||||
a standard library function or function template[.](#namespace.std-7.sentence-1)
|
||||
|
||||
Unless *F* is designated an addressable function,
|
||||
it is unspecified if or how
|
||||
a reflection value designating the associated entity can be formed[.](#namespace.std-7.sentence-2)
|
||||
|
||||
[*Note [3](#namespace.std-note-3)*:
|
||||
|
||||
For example, it is possible that std::meta::members_of will not return reflections of standard library functions
|
||||
that an implementation handles through an extra-linguistic mechanism[.](#namespace.std-7.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[8](#namespace.std-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3095)
|
||||
|
||||
Let *C* denote
|
||||
a standard library class or class template specialization[.](#namespace.std-8.sentence-1)
|
||||
|
||||
It is unspecified if or how
|
||||
a reflection value can be formed to any private member of *C*,
|
||||
or what the names of such members may be[.](#namespace.std-8.sentence-2)
|
||||
|
||||
[9](#namespace.std-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3102)
|
||||
|
||||
A translation unit shall not declare namespace std to be an inline namespace ([[namespace.def]](namespace.def "9.9.2 Namespace definition"))[.](#namespace.std-9.sentence-1)
|
||||
|
||||
[151)](#footnote-151)[151)](#footnoteref-151)
|
||||
|
||||
Any
|
||||
library code that instantiates other library templates
|
||||
must be prepared to work adequately with any user-supplied specialization
|
||||
that meets the minimum requirements of this document[.](#footnote-151.sentence-1)
|
||||
|
||||
#### [16.4.5.2.2](#namespace.posix) Namespace posix [[namespace.posix]](namespace.posix)
|
||||
|
||||
[1](#namespace.posix-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3107)
|
||||
|
||||
The behavior of a C++ program is undefined if it adds declarations or definitions to namespaceposix or to a namespace within namespaceposix unless otherwise specified[.](#namespace.posix-1.sentence-1)
|
||||
|
||||
The namespace posix is reserved for use by
|
||||
ISO/IEC/IEEE 9945 and other POSIX standards[.](#namespace.posix-1.sentence-2)
|
||||
|
||||
#### [16.4.5.2.3](#namespace.future) Namespaces for future standardization [[namespace.future]](namespace.future)
|
||||
|
||||
[1](#namespace.future-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3117)
|
||||
|
||||
Top-level namespaces whose [*namespace-name*](namespace.def.general#nt:namespace-name "9.9.2.1 General [namespace.def.general]") consists of std followed by one or more [*digit*](lex.name#nt:digit "5.11 Identifiers [lex.name]")*s* ([[lex.name]](lex.name "5.11 Identifiers"))
|
||||
are reserved for future standardization[.](#namespace.future-1.sentence-1)
|
||||
|
||||
The behavior of a C++ program is undefined if
|
||||
it adds declarations or definitions to such a namespace[.](#namespace.future-1.sentence-2)
|
||||
|
||||
[*Example [1](#namespace.future-example-1)*:
|
||||
|
||||
The top-level namespace std2 is reserved
|
||||
for use by future revisions of this International Standard[.](#namespace.future-1.sentence-3)
|
||||
|
||||
â *end example*]
|
||||
150
cppdraft/namespace/def.md
Normal file
150
cppdraft/namespace/def.md
Normal file
@@ -0,0 +1,150 @@
|
||||
[namespace.def]
|
||||
|
||||
# 9 Declarations [[dcl]](./#dcl)
|
||||
|
||||
## 9.9 Namespaces [[basic.namespace]](basic.namespace#namespace.def)
|
||||
|
||||
### 9.9.2 Namespace definition [namespace.def]
|
||||
|
||||
#### [9.9.2.1](#general) General [[namespace.def.general]](namespace.def.general)
|
||||
|
||||
[namespace-name:](#nt:namespace-name "9.9.2.1 General [namespace.def.general]")
|
||||
[*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")
|
||||
[*namespace-alias*](namespace.alias#nt:namespace-alias "9.9.3 Namespace alias [namespace.alias]")
|
||||
|
||||
[namespace-definition:](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
[*named-namespace-definition*](#nt:named-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
[*unnamed-namespace-definition*](#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
[*nested-namespace-definition*](#nt:nested-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
|
||||
[named-namespace-definition:](#nt:named-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
inlineopt namespace [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") { [*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") }
|
||||
|
||||
[unnamed-namespace-definition:](#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
inlineopt namespace [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt { [*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") }
|
||||
|
||||
[nested-namespace-definition:](#nt:nested-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
namespace [*enclosing-namespace-specifier*](#nt:enclosing-namespace-specifier "9.9.2.1 General [namespace.def.general]") :: inlineopt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") { [*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") }
|
||||
|
||||
[enclosing-namespace-specifier:](#nt:enclosing-namespace-specifier "9.9.2.1 General [namespace.def.general]")
|
||||
[*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")
|
||||
[*enclosing-namespace-specifier*](#nt:enclosing-namespace-specifier "9.9.2.1 General [namespace.def.general]") :: inlineopt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")
|
||||
|
||||
[namespace-body:](#nt:namespace-body "9.9.2.1 General [namespace.def.general]")
|
||||
[*declaration-seq*](dcl.pre#nt:declaration-seq "9.1 Preamble [dcl.pre]")opt
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8270)
|
||||
|
||||
Every [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") shall inhabit a namespace scope ([[basic.scope.namespace]](basic.scope.namespace "6.4.6 Namespace scope"))[.](#general-1.sentence-1)
|
||||
|
||||
[2](#general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8273)
|
||||
|
||||
In a [*named-namespace-definition*](#nt:named-namespace-definition "9.9.2.1 General [namespace.def.general]") D,
|
||||
the [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") is the name of the namespace[.](#general-2.sentence-1)
|
||||
|
||||
The [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") is looked up
|
||||
by searching for it in the scopes of the namespace A in which D appears
|
||||
and of every element of the inline namespace set of A[.](#general-2.sentence-2)
|
||||
|
||||
If the lookup finds a [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") for a namespace N,D [*extends*](#def:namespace,extend "9.9.2.1 General [namespace.def.general]") N,
|
||||
and the target scope of D is the scope to which N belongs[.](#general-2.sentence-3)
|
||||
|
||||
If the lookup finds nothing, the [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") is introduced
|
||||
as a [*namespace-name*](#nt:namespace-name "9.9.2.1 General [namespace.def.general]") into A[.](#general-2.sentence-4)
|
||||
|
||||
[3](#general-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8287)
|
||||
|
||||
Because a [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") contains[*declaration*](dcl.pre#nt:declaration "9.1 Preamble [dcl.pre]")*s* in its [*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") and a[*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") is itself a [*declaration*](dcl.pre#nt:declaration "9.1 Preamble [dcl.pre]"), it
|
||||
follows that [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]")*s* can be nested[.](#general-3.sentence-1)
|
||||
|
||||
[*Example [1](#general-example-1)*: namespace Outer {int i; namespace Inner {void f() { i++; } // Outer::iint i; void g() { i++; } // Inner::i}} â *end example*]
|
||||
|
||||
[4](#general-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8305)
|
||||
|
||||
If the optional initial inline keyword appears in a[*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") for a particular namespace, that namespace is
|
||||
declared to be an [*inline namespace*](#def:namespace,inline "9.9.2.1 General [namespace.def.general]")[.](#general-4.sentence-1)
|
||||
|
||||
The inline keyword may be
|
||||
used on a [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") that extends a namespace
|
||||
only if it was previously used on the [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") that initially declared the [*namespace-name*](#nt:namespace-name "9.9.2.1 General [namespace.def.general]") for that namespace[.](#general-4.sentence-2)
|
||||
|
||||
[5](#general-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8313)
|
||||
|
||||
The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") in a [*named-namespace-definition*](#nt:named-namespace-definition "9.9.2.1 General [namespace.def.general]") appertains to the namespace being defined or extended[.](#general-5.sentence-1)
|
||||
|
||||
[6](#general-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8318)
|
||||
|
||||
Members of an inline namespace can be used in most respects as though they were members
|
||||
of the innermost enclosing namespace[.](#general-6.sentence-1)
|
||||
|
||||
Specifically, the inline namespace and its enclosing
|
||||
namespace are both added to the set of associated namespaces used in[argument-dependent lookup](basic.lookup.argdep "6.5.4 Argument-dependent name lookup [basic.lookup.argdep]") whenever one of them is,
|
||||
and a [*using-directive*](namespace.udir#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") ([[namespace.udir]](namespace.udir "9.9.4 Using namespace directive")) that names the inline
|
||||
namespace is implicitly inserted into the enclosing namespace as for an unnamed
|
||||
namespace ([[namespace.unnamed]](#namespace.unnamed "9.9.2.2 Unnamed namespaces"))[.](#general-6.sentence-2)
|
||||
|
||||
Furthermore, each
|
||||
member of the inline namespace can subsequently be partially
|
||||
specialized ([[temp.spec.partial]](temp.spec.partial "13.7.6 Partial specialization")), explicitly
|
||||
instantiated ([[temp.explicit]](temp.explicit "13.9.3 Explicit instantiation")), or explicitly specialized ([[temp.expl.spec]](temp.expl.spec "13.9.4 Explicit specialization")) as
|
||||
though it were a member of the enclosing namespace[.](#general-6.sentence-3)
|
||||
|
||||
Finally, looking up a name in the
|
||||
enclosing namespace via explicit qualification ([[namespace.qual]](namespace.qual "6.5.5.3 Namespace members")) will include
|
||||
members of the inline namespace even if
|
||||
there are declarations of that name in the enclosing namespace[.](#general-6.sentence-4)
|
||||
|
||||
[7](#general-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8334)
|
||||
|
||||
These properties are transitive: if a namespace N contains an inline namespaceM, which in turn contains an inline namespace O, then the members ofO can be used as though they were members of M or N[.](#general-7.sentence-1)
|
||||
|
||||
The [*inline namespace set*](#def:inline_namespace_set "9.9.2.1 General [namespace.def.general]") of N is the transitive closure of all
|
||||
inline namespaces in N[.](#general-7.sentence-2)
|
||||
|
||||
[8](#general-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8341)
|
||||
|
||||
A [*nested-namespace-definition*](#nt:nested-namespace-definition "9.9.2.1 General [namespace.def.general]") with an[*enclosing-namespace-specifier*](#nt:enclosing-namespace-specifier "9.9.2.1 General [namespace.def.general]") E,[*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") I and[*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") B is equivalent tonamespace E { inlineopt namespace I { B } } where the optional inline is present if and only if
|
||||
the [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") I is preceded by inline[.](#general-8.sentence-1)
|
||||
|
||||
[*Example [2](#general-example-2)*: namespace A::inline B::C {int i;}
|
||||
|
||||
The above has the same effect as:namespace A {inline namespace B {namespace C {int i; }}}
|
||||
|
||||
â *end example*]
|
||||
|
||||
#### [9.9.2.2](#namespace.unnamed) Unnamed namespaces [[namespace.unnamed]](namespace.unnamed)
|
||||
|
||||
[1](#namespace.unnamed-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8373)
|
||||
|
||||
An [*unnamed-namespace-definition*](#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]") behaves as if it were
|
||||
replaced by
|
||||
|
||||
inlineopt namespace *unique* { /* empty body */ }
|
||||
using namespace *unique* ;
|
||||
namespace *unique* { [*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") }
|
||||
|
||||
whereinline appears if and only if it appears in the[*unnamed-namespace-definition*](#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]") and all occurrences of *unique* in a translation unit are replaced by
|
||||
the same identifier, and this identifier differs from all other
|
||||
identifiers in the program[.](#namespace.unnamed-1.sentence-1)
|
||||
|
||||
The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") in the [*unnamed-namespace-definition*](#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]") appertains to *unique*[.](#namespace.unnamed-1.sentence-2)
|
||||
|
||||
[*Example [1](#namespace.unnamed-example-1)*: namespace { int i; } // *unique*::ivoid f() { i++; } // *unique*::i++namespace A {namespace {int i; // A::*unique*::iint j; // A::*unique*::j}void g() { i++; } // A::*unique*::i++}using namespace A;void h() { i++; // error: *unique*::i or A::*unique*::i A::i++; // A::*unique*::i j++; // A::*unique*::j} â *end example*]
|
||||
129
cppdraft/namespace/def/general.md
Normal file
129
cppdraft/namespace/def/general.md
Normal file
@@ -0,0 +1,129 @@
|
||||
[namespace.def.general]
|
||||
|
||||
# 9 Declarations [[dcl]](./#dcl)
|
||||
|
||||
## 9.9 Namespaces [[basic.namespace]](basic.namespace#namespace.def.general)
|
||||
|
||||
### 9.9.2 Namespace definition [[namespace.def]](namespace.def#general)
|
||||
|
||||
#### 9.9.2.1 General [namespace.def.general]
|
||||
|
||||
[namespace-name:](#nt:namespace-name "9.9.2.1 General [namespace.def.general]")
|
||||
[*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")
|
||||
[*namespace-alias*](namespace.alias#nt:namespace-alias "9.9.3 Namespace alias [namespace.alias]")
|
||||
|
||||
[namespace-definition:](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
[*named-namespace-definition*](#nt:named-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
[*unnamed-namespace-definition*](#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
[*nested-namespace-definition*](#nt:nested-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
|
||||
[named-namespace-definition:](#nt:named-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
inlineopt namespace [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") { [*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") }
|
||||
|
||||
[unnamed-namespace-definition:](#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
inlineopt namespace [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt { [*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") }
|
||||
|
||||
[nested-namespace-definition:](#nt:nested-namespace-definition "9.9.2.1 General [namespace.def.general]")
|
||||
namespace [*enclosing-namespace-specifier*](#nt:enclosing-namespace-specifier "9.9.2.1 General [namespace.def.general]") :: inlineopt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") { [*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") }
|
||||
|
||||
[enclosing-namespace-specifier:](#nt:enclosing-namespace-specifier "9.9.2.1 General [namespace.def.general]")
|
||||
[*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")
|
||||
[*enclosing-namespace-specifier*](#nt:enclosing-namespace-specifier "9.9.2.1 General [namespace.def.general]") :: inlineopt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")
|
||||
|
||||
[namespace-body:](#nt:namespace-body "9.9.2.1 General [namespace.def.general]")
|
||||
[*declaration-seq*](dcl.pre#nt:declaration-seq "9.1 Preamble [dcl.pre]")opt
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8270)
|
||||
|
||||
Every [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") shall inhabit a namespace scope ([[basic.scope.namespace]](basic.scope.namespace "6.4.6 Namespace scope"))[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8273)
|
||||
|
||||
In a [*named-namespace-definition*](#nt:named-namespace-definition "9.9.2.1 General [namespace.def.general]") D,
|
||||
the [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") is the name of the namespace[.](#2.sentence-1)
|
||||
|
||||
The [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") is looked up
|
||||
by searching for it in the scopes of the namespace A in which D appears
|
||||
and of every element of the inline namespace set of A[.](#2.sentence-2)
|
||||
|
||||
If the lookup finds a [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") for a namespace N,D [*extends*](#def:namespace,extend "9.9.2.1 General [namespace.def.general]") N,
|
||||
and the target scope of D is the scope to which N belongs[.](#2.sentence-3)
|
||||
|
||||
If the lookup finds nothing, the [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") is introduced
|
||||
as a [*namespace-name*](#nt:namespace-name "9.9.2.1 General [namespace.def.general]") into A[.](#2.sentence-4)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8287)
|
||||
|
||||
Because a [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") contains[*declaration*](dcl.pre#nt:declaration "9.1 Preamble [dcl.pre]")*s* in its [*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") and a[*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") is itself a [*declaration*](dcl.pre#nt:declaration "9.1 Preamble [dcl.pre]"), it
|
||||
follows that [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]")*s* can be nested[.](#3.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*: namespace Outer {int i; namespace Inner {void f() { i++; } // Outer::iint i; void g() { i++; } // Inner::i}} â *end example*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8305)
|
||||
|
||||
If the optional initial inline keyword appears in a[*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") for a particular namespace, that namespace is
|
||||
declared to be an [*inline namespace*](#def:namespace,inline "9.9.2.1 General [namespace.def.general]")[.](#4.sentence-1)
|
||||
|
||||
The inline keyword may be
|
||||
used on a [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") that extends a namespace
|
||||
only if it was previously used on the [*namespace-definition*](#nt:namespace-definition "9.9.2.1 General [namespace.def.general]") that initially declared the [*namespace-name*](#nt:namespace-name "9.9.2.1 General [namespace.def.general]") for that namespace[.](#4.sentence-2)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8313)
|
||||
|
||||
The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") in a [*named-namespace-definition*](#nt:named-namespace-definition "9.9.2.1 General [namespace.def.general]") appertains to the namespace being defined or extended[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8318)
|
||||
|
||||
Members of an inline namespace can be used in most respects as though they were members
|
||||
of the innermost enclosing namespace[.](#6.sentence-1)
|
||||
|
||||
Specifically, the inline namespace and its enclosing
|
||||
namespace are both added to the set of associated namespaces used in[argument-dependent lookup](basic.lookup.argdep "6.5.4 Argument-dependent name lookup [basic.lookup.argdep]") whenever one of them is,
|
||||
and a [*using-directive*](namespace.udir#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") ([[namespace.udir]](namespace.udir "9.9.4 Using namespace directive")) that names the inline
|
||||
namespace is implicitly inserted into the enclosing namespace as for an unnamed
|
||||
namespace ([[namespace.unnamed]](namespace.unnamed "9.9.2.2 Unnamed namespaces"))[.](#6.sentence-2)
|
||||
|
||||
Furthermore, each
|
||||
member of the inline namespace can subsequently be partially
|
||||
specialized ([[temp.spec.partial]](temp.spec.partial "13.7.6 Partial specialization")), explicitly
|
||||
instantiated ([[temp.explicit]](temp.explicit "13.9.3 Explicit instantiation")), or explicitly specialized ([[temp.expl.spec]](temp.expl.spec "13.9.4 Explicit specialization")) as
|
||||
though it were a member of the enclosing namespace[.](#6.sentence-3)
|
||||
|
||||
Finally, looking up a name in the
|
||||
enclosing namespace via explicit qualification ([[namespace.qual]](namespace.qual "6.5.5.3 Namespace members")) will include
|
||||
members of the inline namespace even if
|
||||
there are declarations of that name in the enclosing namespace[.](#6.sentence-4)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8334)
|
||||
|
||||
These properties are transitive: if a namespace N contains an inline namespaceM, which in turn contains an inline namespace O, then the members ofO can be used as though they were members of M or N[.](#7.sentence-1)
|
||||
|
||||
The [*inline namespace set*](#def:inline_namespace_set "9.9.2.1 General [namespace.def.general]") of N is the transitive closure of all
|
||||
inline namespaces in N[.](#7.sentence-2)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8341)
|
||||
|
||||
A [*nested-namespace-definition*](#nt:nested-namespace-definition "9.9.2.1 General [namespace.def.general]") with an[*enclosing-namespace-specifier*](#nt:enclosing-namespace-specifier "9.9.2.1 General [namespace.def.general]") E,[*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") I and[*namespace-body*](#nt:namespace-body "9.9.2.1 General [namespace.def.general]") B is equivalent tonamespace E { inlineopt namespace I { B } } where the optional inline is present if and only if
|
||||
the [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") I is preceded by inline[.](#8.sentence-1)
|
||||
|
||||
[*Example [2](#example-2)*: namespace A::inline B::C {int i;}
|
||||
|
||||
The above has the same effect as:namespace A {inline namespace B {namespace C {int i; }}}
|
||||
|
||||
â *end example*]
|
||||
28
cppdraft/namespace/future.md
Normal file
28
cppdraft/namespace/future.md
Normal file
@@ -0,0 +1,28 @@
|
||||
[namespace.future]
|
||||
|
||||
# 16 Library introduction [[library]](./#library)
|
||||
|
||||
## 16.4 Library-wide requirements [[requirements]](requirements#namespace.future)
|
||||
|
||||
### 16.4.5 Constraints on programs [[constraints]](constraints#namespace.future)
|
||||
|
||||
#### 16.4.5.2 Namespace use [[namespace.constraints]](namespace.constraints#namespace.future)
|
||||
|
||||
#### 16.4.5.2.3 Namespaces for future standardization [namespace.future]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3117)
|
||||
|
||||
Top-level namespaces whose [*namespace-name*](namespace.def.general#nt:namespace-name "9.9.2.1 General [namespace.def.general]") consists of std followed by one or more [*digit*](lex.name#nt:digit "5.11 Identifiers [lex.name]")*s* ([[lex.name]](lex.name "5.11 Identifiers"))
|
||||
are reserved for future standardization[.](#1.sentence-1)
|
||||
|
||||
The behavior of a C++ program is undefined if
|
||||
it adds declarations or definitions to such a namespace[.](#1.sentence-2)
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
The top-level namespace std2 is reserved
|
||||
for use by future revisions of this International Standard[.](#1.sentence-3)
|
||||
|
||||
â *end example*]
|
||||
20
cppdraft/namespace/posix.md
Normal file
20
cppdraft/namespace/posix.md
Normal file
@@ -0,0 +1,20 @@
|
||||
[namespace.posix]
|
||||
|
||||
# 16 Library introduction [[library]](./#library)
|
||||
|
||||
## 16.4 Library-wide requirements [[requirements]](requirements#namespace.posix)
|
||||
|
||||
### 16.4.5 Constraints on programs [[constraints]](constraints#namespace.posix)
|
||||
|
||||
#### 16.4.5.2 Namespace use [[namespace.constraints]](namespace.constraints#namespace.posix)
|
||||
|
||||
#### 16.4.5.2.2 Namespace posix [namespace.posix]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3107)
|
||||
|
||||
The behavior of a C++ program is undefined if it adds declarations or definitions to namespaceposix or to a namespace within namespaceposix unless otherwise specified[.](#1.sentence-1)
|
||||
|
||||
The namespace posix is reserved for use by
|
||||
ISO/IEC/IEEE 9945 and other POSIX standards[.](#1.sentence-2)
|
||||
67
cppdraft/namespace/qual.md
Normal file
67
cppdraft/namespace/qual.md
Normal file
@@ -0,0 +1,67 @@
|
||||
[namespace.qual]
|
||||
|
||||
# 6 Basics [[basic]](./#basic)
|
||||
|
||||
## 6.5 Name lookup [[basic.lookup]](basic.lookup#namespace.qual)
|
||||
|
||||
### 6.5.5 Qualified name lookup [[basic.lookup.qual]](basic.lookup.qual#namespace.qual)
|
||||
|
||||
#### 6.5.5.3 Namespace members [namespace.qual]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L2574)
|
||||
|
||||
Qualified name lookup in a namespace N additionally searches
|
||||
every element of the inline namespace set of N ([[namespace.def]](namespace.def "9.9.2 Namespace definition"))[.](#1.sentence-1)
|
||||
|
||||
If nothing is found,
|
||||
the results of the lookup are the results of qualified name lookup
|
||||
in each namespace nominated by a [*using-directive*](namespace.udir#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") that precedes the point of the lookup and
|
||||
inhabits N or an element of N's inline namespace set[.](#1.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
If a [*using-directive*](namespace.udir#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") refers to a namespace
|
||||
that has already been considered, it does not affect the result[.](#1.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [1](#example-1)*: int x;namespace Y {void f(float); void h(int);}namespace Z {void h(double);}namespace A {using namespace Y; void f(int); void g(int); int i;}namespace B {using namespace Z; void f(char); int i;}namespace AB {using namespace A; using namespace B; void g();}void h(){ AB::g(); // g is declared directly in AB, therefore S is { AB::g() } and AB::g() is chosen AB::f(1); // f is not declared directly in AB so the rules are applied recursively to A and B;// namespace Y is not searched and Y::f(float) is not considered;// S is { A::f(int), B::f(char) } and overload resolution chooses A::f(int) AB::f('c'); // as above but resolution chooses B::f(char) AB::x++; // x is not declared directly in AB, and is not declared in A or B, so the rules// are applied recursively to Y and Z, S is { } so the program is ill-formed AB::i++; // i is not declared directly in AB so the rules are applied recursively to A and B,// S is { A::i, B::i } so the use is ambiguous and the program is ill-formed AB::h(16.8); // h is not declared directly in AB and not declared directly in A or B so the rules// are applied recursively to Y and Z, S is { Y::h(int), Z::h(double) } and// overload resolution chooses Z::h(double)} â *end example*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L2640)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
The same declaration found more than once is not an ambiguity (because
|
||||
it is still a unique declaration)[.](#2.sentence-1)
|
||||
|
||||
[*Example [2](#example-2)*: namespace A {int a;}namespace B {using namespace A;}namespace C {using namespace A;}namespace BC {using namespace B; using namespace C;}void f(){ BC::a++; // OK, S is { A::a, A::a }}namespace D {using A::a;}namespace BD {using namespace B; using namespace D;}void g(){ BD::a++; // OK, S is { A::a, A::a }} â *end example*]
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L2685)
|
||||
|
||||
[*Example [3](#example-3)*:
|
||||
|
||||
Because each referenced namespace is searched at most once, the
|
||||
following is well-defined:namespace B {int b;}namespace A {using namespace B; int a;}namespace B {using namespace A;}void f(){ A::a++; // OK, a declared directly in A, S is { A::a } B::a++; // OK, both A and B searched (once), S is { A::a } A::b++; // OK, both A and B searched (once), S is { B::b } B::b++; // OK, b declared directly in B, S is { B::b }}
|
||||
|
||||
â *end example*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L2713)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
Class and enumeration declarations are not discarded
|
||||
because of other declarations found in other searches[.](#4.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [4](#example-4)*: namespace A {struct x { }; int x; int y;}namespace B {struct y { };}namespace C {using namespace A; using namespace B; int i = C::x; // OK, A::x (of type int)int j = C::y; // ambiguous, A::y or B::y} â *end example*]
|
||||
171
cppdraft/namespace/std.md
Normal file
171
cppdraft/namespace/std.md
Normal file
@@ -0,0 +1,171 @@
|
||||
[namespace.std]
|
||||
|
||||
# 16 Library introduction [[library]](./#library)
|
||||
|
||||
## 16.4 Library-wide requirements [[requirements]](requirements#namespace.std)
|
||||
|
||||
### 16.4.5 Constraints on programs [[constraints]](constraints#namespace.std)
|
||||
|
||||
#### 16.4.5.2 Namespace use [[namespace.constraints]](namespace.constraints#namespace.std)
|
||||
|
||||
#### 16.4.5.2.1 Namespace std [namespace.std]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2991)
|
||||
|
||||
Unless otherwise specified,
|
||||
the behavior of a C++ program is undefined if it adds declarations or definitions to namespacestd or to a namespace within namespacestd[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2998)
|
||||
|
||||
Unless explicitly prohibited,
|
||||
a program may add a template specialization for
|
||||
any standard library class template
|
||||
to namespacestd provided that
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
the added declaration
|
||||
depends on at least one program-defined type, and
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
the specialization meets the standard library requirements
|
||||
for the original template[.](#2.sentence-1)[151](#footnote-151 "Any library code that instantiates other library templates must be prepared to work adequately with any user-supplied specialization that meets the minimum requirements of this document.")
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3018)
|
||||
|
||||
The behavior of a C++ program is undefined
|
||||
if it declares an explicit or partial specialization
|
||||
of any standard library variable template,
|
||||
except where explicitly permitted by the specification of that variable template[.](#3.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The requirements on an explicit or partial specialization
|
||||
are stated by each variable template that grants such permission[.](#3.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3028)
|
||||
|
||||
The behavior of a C++ program is undefined if it declares
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
an explicit specialization of any member function of a standard
|
||||
library class template, or
|
||||
|
||||
- [(4.2)](#4.2)
|
||||
|
||||
an explicit specialization of any member function template of a
|
||||
standard library class or class template, or
|
||||
|
||||
- [(4.3)](#4.3)
|
||||
|
||||
an explicit or partial specialization of any member class template
|
||||
of a standard library class or class template, or
|
||||
|
||||
- [(4.4)](#4.4)
|
||||
|
||||
a deduction guide for any standard library class template[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3043)
|
||||
|
||||
A program may explicitly instantiate
|
||||
a class template defined in the standard library
|
||||
only if the declaration
|
||||
|
||||
- [(5.1)](#5.1)
|
||||
|
||||
depends on the name of at least one program-defined type, and
|
||||
|
||||
- [(5.2)](#5.2)
|
||||
|
||||
the instantiation meets the standard library requirements for the
|
||||
original template[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3054)
|
||||
|
||||
Let *F* denote
|
||||
a standard library function ([[global.functions]](global.functions "16.4.6.4 Non-member functions")),
|
||||
a standard library static member function,
|
||||
or an instantiation
|
||||
of a standard library function template[.](#6.sentence-1)
|
||||
|
||||
Unless *F* is designated
|
||||
an [*addressable function*](#def:function,addressable "16.4.5.2.1 Namespace std [namespace.std]"),
|
||||
the behavior of a C++ program is unspecified (possibly ill-formed)
|
||||
if it explicitly or implicitly attempts
|
||||
to form a pointer
|
||||
to *F*[.](#6.sentence-2)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
Possible means of forming such pointers include
|
||||
application of the unary & operator ([[expr.unary.op]](expr.unary.op "7.6.2.2 Unary operators")),addressof ([[specialized.addressof]](specialized.addressof "20.2.11 addressof")),
|
||||
or
|
||||
a function-to-pointer standard conversion ([[conv.func]](conv.func "7.3.4 Function-to-pointer conversion"))[.](#6.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
Moreover,
|
||||
the behavior of a C++ program is unspecified (possibly ill-formed)
|
||||
if it attempts to form a reference
|
||||
to *F* or
|
||||
if it attempts to form a pointer-to-member designating
|
||||
either a standard library non-static member function ([[member.functions]](member.functions "16.4.6.5 Member functions"))
|
||||
or an instantiation of a standard library member function template[.](#6.sentence-4)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3082)
|
||||
|
||||
Let *F* denote
|
||||
a standard library function or function template[.](#7.sentence-1)
|
||||
|
||||
Unless *F* is designated an addressable function,
|
||||
it is unspecified if or how
|
||||
a reflection value designating the associated entity can be formed[.](#7.sentence-2)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
For example, it is possible that std::meta::members_of will not return reflections of standard library functions
|
||||
that an implementation handles through an extra-linguistic mechanism[.](#7.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3095)
|
||||
|
||||
Let *C* denote
|
||||
a standard library class or class template specialization[.](#8.sentence-1)
|
||||
|
||||
It is unspecified if or how
|
||||
a reflection value can be formed to any private member of *C*,
|
||||
or what the names of such members may be[.](#8.sentence-2)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3102)
|
||||
|
||||
A translation unit shall not declare namespace std to be an inline namespace ([[namespace.def]](namespace.def "9.9.2 Namespace definition"))[.](#9.sentence-1)
|
||||
|
||||
[151)](#footnote-151)[151)](#footnoteref-151)
|
||||
|
||||
Any
|
||||
library code that instantiates other library templates
|
||||
must be prepared to work adequately with any user-supplied specialization
|
||||
that meets the minimum requirements of this document[.](#footnote-151.sentence-1)
|
||||
300
cppdraft/namespace/udecl.md
Normal file
300
cppdraft/namespace/udecl.md
Normal file
@@ -0,0 +1,300 @@
|
||||
[namespace.udecl]
|
||||
|
||||
# 9 Declarations [[dcl]](./#dcl)
|
||||
|
||||
## 9.10 The using declaration [namespace.udecl]
|
||||
|
||||
[using-declaration:](#nt:using-declaration "9.10 The using declaration [namespace.udecl]")
|
||||
using [*using-declarator-list*](#nt:using-declarator-list "9.10 The using declaration [namespace.udecl]") ;
|
||||
|
||||
[using-declarator-list:](#nt:using-declarator-list "9.10 The using declaration [namespace.udecl]")
|
||||
[*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") ...opt
|
||||
[*using-declarator-list*](#nt:using-declarator-list "9.10 The using declaration [namespace.udecl]") , [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") ...opt
|
||||
|
||||
[using-declarator:](#nt:using-declarator "9.10 The using declaration [namespace.udecl]")
|
||||
typenameopt [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") [*unqualified-id*](expr.prim.id.unqual#nt:unqualified-id "7.5.5.2 Unqualified names [expr.prim.id.unqual]")
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8687)
|
||||
|
||||
The component names of a [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") are those
|
||||
of its [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") and [*unqualified-id*](expr.prim.id.unqual#nt:unqualified-id "7.5.5.2 Unqualified names [expr.prim.id.unqual]")[.](#1.sentence-1)
|
||||
|
||||
Each [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") in a [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]")[84](#footnote-84 "A using-declaration with more than one using-declarator is equivalent to a corresponding sequence of using-declarations with one using-declarator each.") names the set of declarations found by lookup ([[basic.lookup.qual]](basic.lookup.qual "6.5.5 Qualified name lookup"))
|
||||
for the [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]"),
|
||||
except that class and enumeration declarations that would be discarded
|
||||
are merely ignored when checking for ambiguity ([[basic.lookup]](basic.lookup "6.5 Name lookup")),
|
||||
conversion function templates with a dependent return type are ignored, and
|
||||
certain functions are hidden as described below[.](#1.sentence-2)
|
||||
|
||||
If the terminal name of the [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") is dependent ([[temp.dep.type]](temp.dep.type "13.8.3.2 Dependent types")),
|
||||
the [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") is considered to name a constructor
|
||||
if and only if the [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") has a terminal name
|
||||
that is the same as the [*unqualified-id*](expr.prim.id.unqual#nt:unqualified-id "7.5.5.2 Unqualified names [expr.prim.id.unqual]")[.](#1.sentence-3)
|
||||
|
||||
If the lookup in any instantiation finds
|
||||
that a [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") that is not considered to name a constructor does do so, or
|
||||
that a [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") that is considered to name a constructor does not,
|
||||
the program is ill-formed[.](#1.sentence-4)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8716)
|
||||
|
||||
If the [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") names a constructor,
|
||||
it declares that the class [*inherits*](#def:constructor,inherited "9.10 The using declaration [namespace.udecl]") the named set of constructor declarations
|
||||
from the nominated base class[.](#2.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Otherwise,
|
||||
the [*unqualified-id*](expr.prim.id.unqual#nt:unqualified-id "7.5.5.2 Unqualified names [expr.prim.id.unqual]") in the [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") is bound to the [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]"),
|
||||
which is replaced during name lookup
|
||||
with the declarations it names ([[basic.lookup]](basic.lookup "6.5 Name lookup"))[.](#2.sentence-2)
|
||||
|
||||
If such a declaration is of an enumeration,
|
||||
the names of its enumerators are not bound[.](#2.sentence-3)
|
||||
|
||||
For the keyword typename, see [[temp.res]](temp.res "13.8 Name resolution")[.](#2.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8732)
|
||||
|
||||
In a [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") used as a[*member-declaration*](class.mem.general#nt:member-declaration "11.4.1 General [class.mem.general]"),
|
||||
each [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") shall either name an enumerator
|
||||
or have a [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") naming a base class of the current class ([[expr.prim.this]](expr.prim.this "7.5.3 This"))[.](#3.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*: enum class button { up, down };struct S {using button::up;
|
||||
button b = up; // OK}; â *end example*]
|
||||
|
||||
If a[*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") names a constructor,
|
||||
its [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") shall name
|
||||
a direct base class of the current class[.](#3.sentence-2)
|
||||
|
||||
If the immediate (class) scope is associated with a class template,
|
||||
it shall derive from the specified base class or
|
||||
have at least one dependent base class[.](#3.sentence-3)
|
||||
|
||||
[*Example [2](#example-2)*: struct B {void f(char); enum E { e }; union { int x; };};
|
||||
|
||||
struct C {int f();};
|
||||
|
||||
struct D : B {using B::f; // OK, B is a base of Dusing B::e; // OK, e is an enumerator of base Busing B::x; // OK, x is a union member of base Busing C::f; // error: C isn't a base of Dvoid f(int) { f('c'); } // calls B::f(char)void g(int) { g('c'); } // recursively calls D::g(int)};template <typename... bases>struct X : bases... {using bases::f...;};
|
||||
X<B, C> x; // OK, B::f and C::f named â *end example*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8783)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
Since destructors do not have names, a[*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") cannot refer to a
|
||||
destructor for a base class[.](#4.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
If a constructor or assignment operator brought from a base class into a derived class
|
||||
has the signature of a copy/move constructor or assignment operator
|
||||
for the derived class ([[class.copy.ctor]](class.copy.ctor "11.4.5.3 Copy/move constructors"), [[class.copy.assign]](class.copy.assign "11.4.6 Copy/move assignment operator")),
|
||||
the [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") does not by itself
|
||||
suppress the implicit declaration of the derived class member;
|
||||
the member from the base class is hidden or overridden
|
||||
by the implicitly-declared copy/move constructor or assignment operator
|
||||
of the derived class, as described below[.](#4.sentence-2)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8798)
|
||||
|
||||
A [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") shall not name a [*template-id*](temp.names#nt:template-id "13.3 Names of template specializations [temp.names]")[.](#5.sentence-1)
|
||||
|
||||
[*Example [3](#example-3)*: struct A {template <class T> void f(T); template <class T> struct X { };};struct B : A {using A::f<double>; // errorusing A::X<int>; // error}; â *end example*]
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8813)
|
||||
|
||||
A [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") shall not name a namespace[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8816)
|
||||
|
||||
A [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") that names a class member
|
||||
other than an enumerator
|
||||
shall be a[*member-declaration*](class.mem.general#nt:member-declaration "11.4.1 General [class.mem.general]")[.](#7.sentence-1)
|
||||
|
||||
[*Example [4](#example-4)*: struct X {int i; static int s;};
|
||||
|
||||
void f() {using X::i; // error: X::i is a class member and this is not a member declaration.using X::s; // error: X::s is a class member and this is not a member declaration.} â *end example*]
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8835)
|
||||
|
||||
If a declaration is named by two [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]")*s* that inhabit the same class scope, the program is ill-formed[.](#8.sentence-1)
|
||||
|
||||
[*Example [5](#example-5)*: struct C {int i;};
|
||||
|
||||
struct D1 : C { };struct D2 : C { };
|
||||
|
||||
struct D3 : D1, D2 {using D1::i; // OK, equivalent to using C::iusing D1::i; // error: duplicateusing D2::i; // error: duplicate, also names C::i}; â *end example*]
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8855)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
A [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") whose [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]") names a namespace
|
||||
does not name declarations added to the namespace after it[.](#9.sentence-1)
|
||||
|
||||
Thus, additional
|
||||
overloads added after the [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") are ignored, but
|
||||
default function arguments ([[dcl.fct.default]](dcl.fct.default "9.3.4.7 Default arguments")), default template
|
||||
arguments ([[temp.param]](temp.param "13.2 Template parameters")), and
|
||||
template specializations ([[temp.spec.partial]](temp.spec.partial "13.7.6 Partial specialization"), [[temp.expl.spec]](temp.expl.spec "13.9.4 Explicit specialization")) are considered[.](#9.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [6](#example-6)*: namespace A {void f(int);}using A::f; // f is a synonym for A::f; that is, for A::f(int).namespace A {void f(char);}void foo() { f('a'); // calls f(int), even though f(char) exists.}void bar() {using A::f; // f is a synonym for A::f; that is, for A::f(int) and A::f(char). f('a'); // calls f(char)} â *end example*]
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8887)
|
||||
|
||||
If a declaration named by a [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") that inhabits the target scope of another declaration B potentially conflicts with it ([[basic.scope.scope]](basic.scope.scope "6.4.1 General")), and
|
||||
either is reachable from the other, the program is ill-formed
|
||||
unless B is name-independent and
|
||||
the [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") precedes B[.](#10.sentence-1)
|
||||
|
||||
[*Example [7](#example-7)*: int _;void f() {int _; // B _ = 0; using ::_; // error: [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") does not precede B} â *end example*]
|
||||
|
||||
If two declarations named by [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]")*s* that inhabit the same scope potentially conflict,
|
||||
either is reachable from the other, and
|
||||
they do not both declare functions or function templates,
|
||||
the program is ill-formed[.](#10.sentence-2)
|
||||
|
||||
[*Note [4](#note-4)*:
|
||||
|
||||
Overload resolution possibly cannot distinguish
|
||||
between conflicting function declarations[.](#10.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [8](#example-8)*: namespace A {int x; int f(int); int g; void h();}namespace B {int i; struct g { }; struct x { }; void f(int); void f(double); void g(char); // OK, hides struct g}void func() {int i; using B::i; // error: conflictsvoid f(char); using B::f; // OK, each f is a functionusing A::f; // OK, but interferes with B::f(int) f(1); // error: ambiguousstatic_cast<int(*)(int)>(f)(1); // OK, calls A::f f(3.5); // calls B::f(double)using B::g;
|
||||
g('a'); // calls B::g(char)struct g g1; // g1 has class type B::gusing A::g; // error: conflicts with B::gvoid h(); using A::h; // error: conflictsusing B::x; using A::x; // OK, hides struct B::xusing A::x; // OK, does not conflict with previous using A::x x = 99; // assigns to A::xstruct x x1; // x1 has class type B::x} â *end example*]
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8955)
|
||||
|
||||
The set of declarations named by a [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") that inhabits a class C does not include
|
||||
member functions and member function templates of a base class
|
||||
that correspond to (and thus would conflict with)
|
||||
a declaration of a function or function template in C[.](#11.sentence-1)
|
||||
|
||||
[*Example [9](#example-9)*: struct B {virtual void f(int); virtual void f(char); void g(int); void h(int);};
|
||||
|
||||
struct D : B {using B::f; void f(int); // OK, D::f(int) overrides B::f(int);using B::g; void g(char); // OKusing B::h; void h(int); // OK, D::h(int) hides B::h(int)};
|
||||
|
||||
void k(D* p){ p->f(1); // calls D::f(int) p->f('a'); // calls B::f(char) p->g(1); // calls B::g(int) p->g('a'); // calls D::g(char)}struct B1 { B1(int);};
|
||||
|
||||
struct B2 { B2(int);};
|
||||
|
||||
struct D1 : B1, B2 {using B1::B1; using B2::B2;};
|
||||
D1 d1(0); // error: ambiguousstruct D2 : B1, B2 {using B1::B1; using B2::B2;
|
||||
D2(int); // OK, D2::D2(int) hides B1::B1(int) and B2::B2(int)};
|
||||
D2 d2(0); // calls D2::D2(int) â *end example*]
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9013)
|
||||
|
||||
[*Note [5](#note-5)*:
|
||||
|
||||
For the purpose of forming a set of candidates during overload resolution,
|
||||
the functions
|
||||
named by a [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") in a derived class
|
||||
are treated as though they were direct members of the derived class[.](#12.sentence-1)
|
||||
|
||||
In
|
||||
particular, the implicit object parameter is treated as if
|
||||
it were a reference to the derived class rather than to the base class ([[over.match.funcs]](over.match.funcs "12.2.2 Candidate functions and argument lists"))[.](#12.sentence-2)
|
||||
|
||||
This has no effect on the type of the function, and in all other
|
||||
respects the function remains part of the base class[.](#12.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9026)
|
||||
|
||||
Constructors that are named by a [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") are treated as though they were constructors of the derived class
|
||||
when looking up the constructors of the derived class ([[class.qual]](class.qual "6.5.5.2 Class members"))
|
||||
or forming a set of overload candidates ([[over.match.ctor]](over.match.ctor "12.2.2.4 Initialization by constructor"), [[over.match.copy]](over.match.copy "12.2.2.5 Copy-initialization of class by user-defined conversion"), [[over.match.list]](over.match.list "12.2.2.8 Initialization by list-initialization"))[.](#13.sentence-1)
|
||||
|
||||
[*Note [6](#note-6)*:
|
||||
|
||||
If such a constructor is selected to perform the initialization
|
||||
of an object of class type, all subobjects other than the base class
|
||||
from which the constructor originated
|
||||
are implicitly initialized ([[class.inhctor.init]](class.inhctor.init "11.9.4 Initialization by inherited constructor"))[.](#13.sentence-2)
|
||||
|
||||
A constructor of a derived class is sometimes preferred to a constructor of a base class
|
||||
if they would otherwise be ambiguous ([[over.match.best]](over.match.best "12.2.4 Best viable function"))[.](#13.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9040)
|
||||
|
||||
In a [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") that does not name a constructor,
|
||||
every declaration named shall be accessible[.](#14.sentence-1)
|
||||
|
||||
In a [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") that names a constructor,
|
||||
no access check is performed[.](#14.sentence-2)
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9047)
|
||||
|
||||
[*Note [7](#note-7)*:
|
||||
|
||||
Because a [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") designates a base class member
|
||||
(and not a member subobject or a member function of a base class
|
||||
subobject), a [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") cannot be used to resolve
|
||||
inherited member ambiguities[.](#15.sentence-1)
|
||||
|
||||
[*Example [10](#example-10)*: struct A { int x(); };struct B : A { };struct C : A {using A::x; int x(int);};
|
||||
|
||||
struct D : B, C {using C::x; int x(double);};int f(D* d) {return d->x(); // error: overload resolution selects A::x, but A is an ambiguous base class} â *end example*]
|
||||
|
||||
â *end note*]
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L9073)
|
||||
|
||||
A [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") has the usual
|
||||
accessibility for a [*member-declaration*](class.mem.general#nt:member-declaration "11.4.1 General [class.mem.general]")[.](#16.sentence-1)
|
||||
|
||||
Base-class constructors considered because of a [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") are accessible if they would be accessible
|
||||
when used to construct an object of the base class;
|
||||
the accessibility of the [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") is ignored[.](#16.sentence-2)
|
||||
|
||||
[*Example [11](#example-11)*: class A {private:void f(char);public:void f(int);protected:void g();};
|
||||
|
||||
class B : public A {using A::f; // error: A::f(char) is inaccessiblepublic:using A::g; // B::g is a public synonym for A::g}; â *end example*]
|
||||
|
||||
[84)](#footnote-84)[84)](#footnoteref-84)
|
||||
|
||||
A [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]") with more than one[*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") is equivalent to a corresponding sequence
|
||||
of [*using-declaration*](#nt:using-declaration "9.10 The using declaration [namespace.udecl]")*s* with
|
||||
one [*using-declarator*](#nt:using-declarator "9.10 The using declaration [namespace.udecl]") each[.](#footnote-84.sentence-1)
|
||||
143
cppdraft/namespace/udir.md
Normal file
143
cppdraft/namespace/udir.md
Normal file
@@ -0,0 +1,143 @@
|
||||
[namespace.udir]
|
||||
|
||||
# 9 Declarations [[dcl]](./#dcl)
|
||||
|
||||
## 9.9 Namespaces [[basic.namespace]](basic.namespace#namespace.udir)
|
||||
|
||||
### 9.9.4 Using namespace directive [namespace.udir]
|
||||
|
||||
[using-directive:](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]")
|
||||
[*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt using namespace [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]")opt [*namespace-name*](namespace.def.general#nt:namespace-name "9.9.2.1 General [namespace.def.general]") ;
|
||||
[*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt using namespace [*splice-specifier*](basic.splice#nt:splice-specifier "6.6 Splice specifiers [basic.splice]") ;
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8464)
|
||||
|
||||
The [*splice-specifier*](basic.splice#nt:splice-specifier "6.6 Splice specifiers [basic.splice]") (if any) shall designate a namespace
|
||||
that is not the global namespace[.](#1.sentence-1)
|
||||
|
||||
The [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]"),[*namespace-name*](namespace.def.general#nt:namespace-name "9.9.2.1 General [namespace.def.general]"), and[*splice-specifier*](basic.splice#nt:splice-specifier "6.6 Splice specifiers [basic.splice]") shall not be dependent[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8472)
|
||||
|
||||
A [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") shall not appear in class scope, but may
|
||||
appear in namespace scope or in block scope[.](#2.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
When looking up a [*namespace-name*](namespace.def.general#nt:namespace-name "9.9.2.1 General [namespace.def.general]") in a[*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]"), only namespace names are considered,
|
||||
see [[basic.lookup.udir]](basic.lookup.udir "6.5.7 Using-directives and namespace aliases")[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") appertains to the [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]")[.](#2.sentence-3)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8482)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
A [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") makes the names in the designated
|
||||
namespace usable in the scope in which the[*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") appears after
|
||||
the [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") ([[basic.lookup.unqual]](basic.lookup.unqual "6.5.3 Unqualified name lookup"), [[namespace.qual]](namespace.qual "6.5.5.3 Namespace members"))[.](#3.sentence-1)
|
||||
|
||||
During unqualified name lookup, the names
|
||||
appear as if they were declared in the nearest enclosing namespace which
|
||||
contains both the [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") and the designated
|
||||
namespace[.](#3.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8494)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
A [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") does not introduce any names[.](#4.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [1](#example-1)*: namespace A {int i; namespace B {namespace C {int i; }using namespace A::B::C; void f1() { i = 5; // OK, C::i visible in B and hides A::i}}namespace D {using namespace B; using namespace C; void f2() { i = 5; // ambiguous, B::C::i or A::i?}}void f3() { i = 5; // uses A::i}}void f4() { i = 5; // error: neither i is visible} â *end example*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8528)
|
||||
|
||||
[*Note [4](#note-4)*:
|
||||
|
||||
A [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") is transitive: if a scope contains a[*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") that designates a namespace that itself
|
||||
contains [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]")*s*, the namespaces designated by those[*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]")*s* are also eligible to be considered[.](#5.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [2](#example-2)*: namespace M {int i;}namespace N {int i; using namespace M;}void f() {using namespace N;
|
||||
i = 7; // error: both M::i and N::i are visible}
|
||||
|
||||
For another example,namespace A {int i;}namespace B {int i; int j; namespace C {namespace D {using namespace A; int j; int k; int a = i; // B::i hides A::i}using namespace D; int k = 89; // no problem yetint l = k; // ambiguous: C::k or D::kint m = i; // B::i hides A::iint n = j; // D::j hides B::j}}
|
||||
|
||||
â *end example*]
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8578)
|
||||
|
||||
[*Note [5](#note-5)*:
|
||||
|
||||
Declarations in a namespace
|
||||
that appear after a [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") for that namespace
|
||||
can be found through that [*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]") after they appear[.](#6.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8585)
|
||||
|
||||
[*Note [6](#note-6)*:
|
||||
|
||||
If name lookup finds a declaration for a name in two different
|
||||
namespaces, and the declarations do not declare the same entity and do
|
||||
not declare functions or function templates, the use of the name is ill-formed ([[basic.lookup]](basic.lookup "6.5 Name lookup"))[.](#7.sentence-1)
|
||||
|
||||
In particular, the name of a variable, function or enumerator does not
|
||||
hide the name of a class or enumeration declared in a different
|
||||
namespace[.](#7.sentence-2)
|
||||
|
||||
For example,namespace A {class X { }; extern "C" int g(); extern "C++" int h();}namespace B {void X(int); extern "C" int g(); extern "C++" int h(int);}using namespace A;using namespace B;
|
||||
|
||||
void f() { X(1); // error: name X found in two namespaces g(); // OK, name g refers to the same entity h(); // OK, overload resolution selects A::h}
|
||||
|
||||
â *end note*]
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8615)
|
||||
|
||||
[*Note [7](#note-7)*:
|
||||
|
||||
The order in which namespaces are considered and the
|
||||
relationships among the namespaces implied by the[*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]")*s* do not affect overload resolution[.](#8.sentence-1)
|
||||
|
||||
Neither is any function excluded because another has the same
|
||||
signature, even if one is in a namespace reachable through[*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]")*s* in the namespace of the other[.](#8.sentence-2)[83](#footnote-83 "During name lookup in a class hierarchy, some ambiguities can be resolved by considering whether one member hides the other along some paths ([class.member.lookup]). There is no such disambiguation when considering the set of names found as a result of following using-directives.")
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [3](#example-3)*: namespace D {int d1; void f(char);}using namespace D;
|
||||
|
||||
int d1; // OK, no conflict with D::d1namespace E {int e; void f(int);}namespace D { // namespace extensionint d2; using namespace E; void f(int);}void f() { d1++; // error: ambiguous ::d1 or D::d1?::d1++; // OK D::d1++; // OK d2++; // OK, D::d2 e++; // OK, E::e f(1); // error: ambiguous: D::f(int) or E::f(int)? f('a'); // OK, D::f(char)} â *end example*]
|
||||
|
||||
[83)](#footnote-83)[83)](#footnoteref-83)
|
||||
|
||||
During
|
||||
name lookup in a class hierarchy, some ambiguities can be
|
||||
resolved by considering whether one member hides the other along some
|
||||
paths ([[class.member.lookup]](class.member.lookup "6.5.2 Member name lookup"))[.](#footnote-83.sentence-1)
|
||||
|
||||
There is no such disambiguation when
|
||||
considering the set of names found as a result of following[*using-directive*](#nt:using-directive "9.9.4 Using namespace directive [namespace.udir]")*s*[.](#footnote-83.sentence-2)
|
||||
28
cppdraft/namespace/unnamed.md
Normal file
28
cppdraft/namespace/unnamed.md
Normal file
@@ -0,0 +1,28 @@
|
||||
[namespace.unnamed]
|
||||
|
||||
# 9 Declarations [[dcl]](./#dcl)
|
||||
|
||||
## 9.9 Namespaces [[basic.namespace]](basic.namespace#namespace.unnamed)
|
||||
|
||||
### 9.9.2 Namespace definition [[namespace.def]](namespace.def#namespace.unnamed)
|
||||
|
||||
#### 9.9.2.2 Unnamed namespaces [namespace.unnamed]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L8373)
|
||||
|
||||
An [*unnamed-namespace-definition*](namespace.def.general#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]") behaves as if it were
|
||||
replaced by
|
||||
|
||||
inlineopt namespace *unique* { /* empty body */ }
|
||||
using namespace *unique* ;
|
||||
namespace *unique* { [*namespace-body*](namespace.def.general#nt:namespace-body "9.9.2.1 General [namespace.def.general]") }
|
||||
|
||||
whereinline appears if and only if it appears in the[*unnamed-namespace-definition*](namespace.def.general#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]") and all occurrences of *unique* in a translation unit are replaced by
|
||||
the same identifier, and this identifier differs from all other
|
||||
identifiers in the program[.](#1.sentence-1)
|
||||
|
||||
The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") in the [*unnamed-namespace-definition*](namespace.def.general#nt:unnamed-namespace-definition "9.9.2.1 General [namespace.def.general]") appertains to *unique*[.](#1.sentence-2)
|
||||
|
||||
[*Example [1](#example-1)*: namespace { int i; } // *unique*::ivoid f() { i++; } // *unique*::i++namespace A {namespace {int i; // A::*unique*::iint j; // A::*unique*::j}void g() { i++; } // A::*unique*::i++}using namespace A;void h() { i++; // error: *unique*::i or A::*unique*::i A::i++; // A::*unique*::i j++; // A::*unique*::j} â *end example*]
|
||||
Reference in New Issue
Block a user