In general, whenever a name is encountered
it is necessary to look it up ([basic.lookup])
to determine whether that name denotes one of these entities
before continuing to parse the program that contains it.
An entity is a
variable,
structured binding,
result binding,
function,
enumerator,
type,
type alias,
non-static data member,
bit-field,
template,
namespace,
namespace alias,
template parameter,
function parameter, or
init-capture.
The underlying entity of an entity is that entity
unless otherwise specified.
A name denotes the underlying entity of
the entity declared by each declaration that introduces the name.
A name used in more than one translation unit can potentially
refer to the same entity in these translation units depending on the
linkage of the name specified in each
translation unit.
A declaration ([basic.pre]) may (re)introduce
one or more names and/or entities into a translation
unit.
If so, the
declaration specifies the interpretation and semantic properties of these names.
A declaration of an entity X is
a redeclaration of X
if another declaration of X is reachable from it ([module.reach]);
otherwise, it is a first declaration.
it declares a static data member outside a class definition
and the variable was defined within the class with the constexpr
specifier ([class.static.data]) (this usage is deprecated; see [depr.static.constexpr]),
All but one of the following are definitions:
int a; / defines aexternconstint c =1; / defines cint f(int x){return x+a; }/ defines f and defines xstruct S {int a; int b; }; / defines S, S::a, and S::bstruct X {/ defines Xint x; / defines non-static data member xstaticint y; / declares static data member y
X(): x(0){}/ defines a constructor of X};
int X::y =1; / defines X::yenum{ up, down }; / defines up and downnamespace N {int d; }/ defines N and N::d
X anX; / defines anX
whereas these are just declarations:
externint a; / declares aexternconstint c; / declares cint f(int); / declares fstruct S; / declares Stypedefint Int; / declares Intnamespace N1 = N; / declares N1extern X anotherX; / declares anotherXusing N::d; / declares d
In some circumstances, C++ implementations implicitly define the
default constructor ([class.default.ctor]),
copy constructor, move constructor ([class.copy.ctor]),
copy assignment operator, move assignment operator ([class.copy.assign]),
or destructor member functions.
Given
#include<string>struct C {
std::string s; / std::string is the standard library class ([string.classes])};
int main(){
C a;
C b = a;
b = a;
}
the implementation will implicitly define functions to make the
definition of C equivalent to
struct C {
std::string s;
C(): s(){}
C(const C& x): s(x.s){}
C(C&& x): s(static_cast<std::string&&>(x.s)){}/ : s(std::move(x.s)) { }
C&operator=(const C& x){ s = x.s; return*this; }
C&operator=(C&& x){ s =static_cast<std::string&&>(x.s); return*this; }/ { s = std::move(x.s); return *this; }~C(){}};
In the definition of an object,
the type of that object shall not be
an incomplete type ([basic.types.general]),
an abstract class type ([class.abstract]), or
a (possibly multidimensional) array thereof.
An expression or conversion is potentially evaluated unless it is
an unevaluated operand ([expr.context]),
a subexpression thereof, or
a conversion in an initialization or conversion sequence in such a context.
The set of potential results of an expression E is
defined as follows:
If E is a class member access
expression ([expr.ref]) of the form
E1.templateoptE2,
where E2 designates a non-static data member or
a direct base class relationship,
the set contains the potential results of E1.
In the following example, the set of potential results of the initializer
of n contains the first S::x subexpression, but not the second
S::x subexpression.
The set of potential results of the initializer of o contains
the subexpression [:^S::x:].
struct S {staticconstint x =0; };
constint&f(constint&r);
int n = b ?(1, S::x)/ S::x is not odr-used here: f(S::x); / S::x is odr-used here, so a definition is requiredint o =[:^S::x:];
— end example]
A function is named by an expression or conversion
if it is the selected member
of an overload set ([basic.lookup], [over.match], [over.over])
in an overload resolution performed
as part of forming that expression or conversion,
and either
it is not a pure virtual function or
the expression is an id-expression naming the function with
an explicitly qualified name
that does not form a pointer to member ([expr.unary.op]).
A constructor selected to copy or move an object of class type
is considered to be named by an expression or conversion
even if the call is actually elided by the implementation ([class.copy.elision]).
A deallocation function for a class
is named by a new-expression
if it is the single matching deallocation function
for the allocation function selected by overload resolution,
as specified in [expr.new].
E is a class member access expression ([expr.ref])
naming a non-static data member of reference type and
whose object expression has non-volatile-qualified type, or
the lvalue-to-rvalue conversion ([conv.lval]) is applied to E and
E has non-volatile-qualified non-class type.
[Example 2: int f(int);
int g(int&);
struct A {int x;
};
struct B {int& r;
};
int h(bool cond){constexpr A a ={1};
constexprconstvolatile A& r = a; / odr-uses aint _ = f(cond ? a.x : r.x); / does not odr-use a or rint x, y;
constexpr B b1 ={x}, b2 ={y}; / odr-uses x and yint _ = g(cond ? b1.r : b2.r); / does not odr-use b1 or b2int _ =((cond ? x : y), 0); / does not odr-use x or yreturn[]{return b1.r; / error: b1 is odr-used here because the object/ referred to by b1.r is not constexpr-referenceable here}();
} — end example]
A structured binding is named by an expression
if that expression is either an id-expression or
a splice-expression
that designates that structured binding.
A structured binding is odr-used
if it is named by a potentially-evaluated expression.
*this is odr-used if this appears as a potentially-evaluated expression
(including as the result of any implicit transformation to
a class member access expression ([expr.prim.id.general])).
A virtual member
function is odr-used if it is not pure.
A function is odr-used if it is named by
a potentially-evaluated expression or conversion.
A non-placement allocation or deallocation
function for a class is odr-used by the definition of a constructor of that
class.
A non-placement deallocation function for a class is odr-used by the
definition of the destructor of that class, or by being selected by the
lookup at the point of definition of a virtual
destructor ([class.dtor]).13
An assignment operator function in a class is odr-used by an
implicitly-defined
copy assignment or move assignment function for another class as specified
in [class.copy.assign].
A constructor for a class is odr-used as specified
in [dcl.init].
either the local entity is not *this, or
an enclosing class or non-lambda function parameter scope exists and,
if the innermost such scope is a function parameter scope,
it corresponds to a non-static member function, and
for each intervening scope ([basic.scope.scope])
between the point at which the entity is introduced and the scope
(where *this is considered to be introduced
within the innermost enclosing class or non-lambda function parameter scope),
either
If a local entity is odr-used
in a scope in which it is not odr-usable,
the program is ill-formed.
[Example 3: void f(int n){[]{ n =1; }; / error: n is not odr-usable due to intervening lambda-expressionstruct A {void f(){ n =2; }/ error: n is not odr-usable due to intervening function parameter scope};
void g(int= n); / error: n is not odr-usable due to intervening function parameter scope[=](int k = n){}; / error: n is not odr-usable due to being/ outside the block scope of the lambda-expression[&]{[n]{return n; }; }; / OK} — end example]
[Example 4: void g(){constexprint x =1;
auto lambda =[]<typename T, int=((T)x, 0)>{}; / OK
lambda.operator()<int, 1>(); / OK, does not consider x at all
lambda.operator()<int>(); / OK, does not odr-use x
lambda.operator()<constint&>(); / error: odr-uses x from a context where x is not odr-usable}void h(){constexprint x =1;
auto lambda =[]<typename T>{(T)x; }; / OK
lambda.operator()<int>(); / OK, does not odr-use x
lambda.operator()<void>(); / OK, does not odr-use x
lambda.operator()<constint&>(); / error: odr-uses x from a context where x is not odr-usable} — end example]
Every program shall contain at least one definition of every
function or variable that is odr-used in that program
outside of a discarded statement; no diagnostic required.
[Example 5: auto f(){struct A {};
return A{};
}decltype(f() g();
auto x = g();
A program containing this translation unit is ill-formed
because g is odr-used but not defined,
and cannot be defined in any other translation unit
because the local class A cannot be named outside this
translation unit.
A definition of an inline function or variable shall be reachable
from the end of every definition domain
in which it is odr-used outside of a discarded statement.
The following complete translation unit is well-formed,
even though it never defines X:
struct X; / declare X as a struct typestruct X* x1; / use X in pointer formation
X* x2; / use X in pointer formation
an expression that is not a null pointer constant, and has type
other than cvvoid*, is converted to the type pointer to T
or reference to T using a standard conversion ([conv]),
a dynamic_cast ([expr.dynamic.cast]) or
a static_cast ([expr.static.cast]), or
If a definable item D is defined in a translation unit
by an injected declaration X ([expr.const]) and
another translation unit contains a definition of D,
that definition shall be an injected declaration
having the same characteristic sequence as X;
a diagnostic is required only if D is attached to a named module and
a prior definition is reachable at the point where a later definition occurs.
if the definitions in different translation units
do not satisfy the following requirements,
the program is ill-formed;
a diagnostic is required only
if the definable item is attached to a named module and
a prior definition is reachable at the point where a later definition occurs.
Given such an item,
for all definitions of D, or,
if D is an unnamed enumeration,
for all definitions of D that are reachable at any given program point,
the following requirements shall be satisfied.
Each such definition shall consist of
the same sequence of tokens,
where the definition of a closure type
is considered to consist of the sequence of tokens of
the corresponding lambda-expression.
In each such definition, corresponding names, looked up
according to [basic.lookup], shall denote the same entity, after
overload resolution ([over.match]) and after matching of partial
template specializations ([temp.spec.partial.match]), except that a name can refer to
a reference with internal or no linkage
initialized with a constant expression such that
the reference refers to the same object or function in all definitions of D.
In each such definition, except within
the default arguments and default template arguments of D,
corresponding lambda-expressions shall have
the same closure type (see below).
In each such definition,
const objects with static or thread storage duration
shall be constant-initialized if
the object is constant-initialized in any such definition.
In each such definition,
corresponding manifestly constant-evaluated expressions
that are not value-dependent
shall have the same value ([expr.const], [temp.dep.constexpr]).
In each such definition, the overloaded operators referred
to, the implicit calls to conversion functions, constructors, operator
new functions and operator delete functions, shall refer to the same
function.
In each such definition,
a default argument used by an (implicit or explicit) function call or
a default template argument used by an (implicit or explicit)
template-id,
simple-template-id, or
splice-specialization-specifier
is treated as if its token sequence
were present in the definition of D;
that is, the default argument or default template argument
is subject to the requirements described in this paragraph (recursively).
If D is a class with an implicitly-declared
constructor ([class.default.ctor], [class.copy.ctor]),
it is as if the constructor was
implicitly defined in every translation unit where it is odr-used, and the
implicit definition in every translation unit shall call the same
constructor for a subobject of D.
[Example 7: / translation unit 1:struct X {
X(int, int);
X(int, int);
};
X::X(int, int=0){}class D {
X x =0;
};
D d1; / X(int, int) called by D()/ translation unit 2:struct X {
X(int, int);
X(int, int);
};
X::X(int, int=0, int=0){}class D {
X x =0;
};
D d2; / X(int, int, int) called by D();/ D()'s implicit definition violates the ODR — end example]
If D is a class with
a defaulted three-way comparison operator function ([class.spaceship]),
it is as if the operator was
implicitly defined in every translation unit where it is odr-used, and the
implicit definition in every translation unit shall call the same
comparison operators for each subobject of D.
If D is a template and is defined in more than one
translation unit, the requirements
apply both to names from the template's enclosing scope used in the
template definition, and also to dependent names at
the point of instantiation ([temp.dep]).
These requirements also apply to corresponding entities
defined within each definition of D
(including the closure types of lambda-expressions,
but excluding entities defined within default arguments or
default template arguments of either D or
an entity not defined within D).
For each such entity and for D itself,
the behavior is as if there is a single entity with a single definition,
including in the application of these requirements to other entities.
The entity is still declared in multiple translation units, and [basic.link]
still applies to these declarations.
In particular,
lambda-expressions ([expr.prim.lambda])
appearing in the type of D can result
in the different declarations having distinct types, and
lambda-expressions appearing in a default argument of D
might still denote different types in different translation units.
If the definition of f appears in multiple translation units,
the behavior of the program is as if
there is only one definition of f.
If the definition of g appears in multiple translation units,
the program is ill-formed (no diagnostic required) because
each such definition uses a default argument that
refers to a distinct lambda-expression closure type.
The definition of X can appear
in multiple translation units of a valid program;
the lambda-expressions defined within
the default argument of X::h within the definition of X
denote the same closure type in each translation unit.
If, at any point in the program,
there is more than one
reachable unnamed enumeration definition in the same scope
that have the same first enumerator name and
do not have typedef names for linkage purposes ([dcl.enum]),
those unnamed enumeration types shall be the same; no diagnostic required.
An implementation is not required
to call allocation and
deallocation functions from constructors or destructors; however, this
is a permissible implementation technique.
Friend declarations and
declarations of template specializations do not bind names ([dcl.meaning]);
those with qualified names target a specified scope, and
other friend declarations and
certain elaborated-type-specifiers ([dcl.type.elab])
target a larger enclosing scope.
exactly one is an implicit object member function
with no ref-qualifier and
the types of their object parameters ([dcl.fct]),
after removing references,
are the same, or
exactly one is an implicit object member function
with no ref-qualifier and
the types of their object parameters,
after removing any references,
are equivalent, or
the types of their object parameters are equivalent.
Two function templates have
corresponding signatures if
their template-parameter-lists
have the same length,
their corresponding template-parameters are equivalent,
they have equivalent non-object-parameter-type-lists and return types (if any), and,
if both are non-static members, they have corresponding object parameters.
one declares a type (not a type alias) and the other declares a
variable,
non-static data member other than of an anonymous union ([class.union.anon]),
enumerator,
function, or
function template, or
both declare functions with the same non-object-parameter-type-list,14
equivalent ([temp.over.link]) trailing requires-clauses
(if any, except as specified in [temp.friend]), and,
if both are non-static members,
they have corresponding object parameters, or
The program is ill-formed
if, in any scope, a name is bound to two declarations A and B
that potentially conflict and A precedes B ([basic.lookup]),
unless B is name-independent.
An id-expression that names a unique name-independent declaration
is usable until an additional declaration of the same name
is introduced in the same scope ([basic.lookup.general]).
Overload resolution can consider potentially conflicting declarations
found in multiple scopes
(e.g., via using-directives or for operator functions),
in which case it is often ambiguous.
— end note]
[Example 3: void f(){int x,y;
void x(); / error: different entity for xint y; / error: redefinition}enum{ f }; / error: different entity for ::fnamespace A {}namespace B = A;
namespace B = A; / OK, no effectnamespace B = B; / OK, no effectnamespace A = B; / OK, no effectnamespace B {}/ error: different entity for Bvoid g(){int _;
_ =0; / OKint _; / OK, name-independent declaration
_ =0; / error: two non-function declarations in the lookup set}void h (){int _; / #1
_ ++; / OKstaticint _; / error: conflicts with #1 because static variables are not name-independent} — end example]
A declaration is nominable
in a class, class template, or namespace E at a point P if
it precedes P,
it does not inhabit a block scope, and
its target scope is the scope associated with E or,
if E is a namespace,
any element of the inline namespace set of E ([namespace.def]).
[Example 4: namespace A {void f(){void g();}inlinenamespace B {struct S {friendvoid h();
staticint i;
};
}}
At the end of this example,
the declarations of f, B, S, and h
are nominable in A, but those of g and i are not.
When instantiating a templated entity ([temp.pre]),
any scope S introduced by any part of the template definition is considered
to be introduced by the instantiated entity and
to contain the instantiations of any declarations that inhabit S.
The locus of the implicit declaration of
a function-local predefined variable ([dcl.fct.def.general])
is immediately before
the function-body of its function's definition.
The locus of the declaration of a structured binding ([dcl.struct.bind])
is immediately after
the identifier-list of the structured binding declaration.
[Example 5: typedefunsignedchar T;
template<class T
= T / lookup finds the typedef-name
, T / lookup finds the template parameter
N =0>struct A {};
— end example]
Friend declarations can introduce functions or classes
that belong to the nearest enclosing namespace or block scope,
but they do not bind names anywhere ([class.friend]).
Function declarations at block scope and
variable declarations with the extern specifier at block scope
declare entities
that belong to the nearest enclosing namespace,
but they do not bind names in it.
For each non-friend redeclaration or specialization
whose target scope is or is contained by the scope,
the portion after the
declarator-id,
class-head-name, or
enum-head-name
is also included in the scope.
The global scope is
the namespace scope of the global namespace ([basic.namespace]).
[Example 1: namespace Q {namespace V {void f(); }void V::f(){/ in the scope of Vvoid h(); / declares Q::V::h}} — end example]
For each non-friend redeclaration or specialization
whose target scope is or is contained by the scope,
the portion after the
declarator-id,
class-head-name, or
enum-head-name is also included in the scope.
Lookup from a program point
before the class-specifier of a class
will find no bindings in the class scope.
[Example 1: template<class D>struct B {
D::type x; / #1};
struct A {using type =int; };
struct C : A, B<C>{}; / error at #1: C::type not found — end example]
Therefore, only template parameters belong to a template parameter scope, and
only template parameter scopes have
a template parameter scope as a parent scope.
If a result-name-introducer ([dcl.contract.res])
that is not name-independent ([basic.scope.scope])
and whose enclosing postcondition assertion
is associated with a function F
potentially conflicts with
a declaration whose target scope is
The access rules ([class.access])
are considered only once name lookup and
function overload resolution (if applicable) have succeeded.
Only after
name lookup, function overload resolution (if applicable) and access
checking have succeeded
are the semantic properties introduced by the declarations
used in further processing.
The declaration might appear in a scope that does not contain P.
— end note]
A declaration Xprecedes
a program point P in a translation unit L
if P follows X, X inhabits a class scope and is reachable from P, or
else X appears in a translation unit D and
either X is exported or else D and L are part of the same module and
X does not inhabit a namespace with internal linkage or
declare a name with internal linkage.
A single search in a scope S
for a name N from a program point P
finds all declarations that precede P
to which any name that is the same as N ([basic.pre]) is bound in S.
A type (but not a type alias or template)
is therefore hidden by any other entity in its scope.
— end note]
However, if a lookup is type-only,
only declarations of
types and templates whose specializations are types are considered;
furthermore, if declarations
of a type alias and of its underlying entity are found,
the declaration of the type alias is discarded
instead of the type declaration.
A search in a scope X for a name M from a program point P
is a single search in X for M from P
unless X is the scope of a class or class template T, in which case the
following steps define the result of the search.
The lookup set for a name N in a class or class template C, called S(N,C),
consists of two component sets:
the declaration set, a set of members named N; and
the subobject set,
a set of subobjects where declarations of these members were found
(possibly via using-declarations).
In the declaration set, type declarations (including injected-class-names)
are replaced by the types they designate.
The declaration set is the result of
a single search in the scope of C for N
from immediately after the class-specifier of C
if P is in a complete-class context of C or
from P otherwise.
If the resulting declaration set is not empty, the subobject set
contains C itself, and calculation is complete.
Otherwise (i.e., C does not contain a declaration of N
or the resulting declaration set is empty), S(N,C) is initially empty.
Calculate the lookup set for N
in each direct non-dependent ([temp.dep.type]) base class subobject Bi, and
merge each such lookup set S(N,Bi) in turn into S(N,C).
If each of the subobject members of S(N,Bi) is a base class
subobject of at least one of the subobject members of S(N,C), or if
S(N,Bi) is empty, S(N,C) is unchanged and the merge is complete.
Conversely, if each of the subobject members of S(N,C) is a base class
subobject of at least one of the subobject members of S(N,Bi), or if
S(N,C) is empty, the new S(N,C) is a copy of S(N,Bi).
Otherwise, if the declaration sets of S(N,Bi) and S(N,C)
differ, the merge is ambiguous: the new S(N,C) is a lookup set with an
invalid declaration set and the union of the subobject sets.
In
subsequent merges, an invalid declaration set is considered different
from any other.
The result of the search is the declaration set of S(M,T).
If it is an invalid set, the program is ill-formed.
If it differs from the result of a search in T for M
in a complete-class context ([class.mem]) of T,
the program is ill-formed, no diagnostic required.
[Example 1: struct A {int x; }; / S(x,A) = { { A::x }, { A } }struct B {float x; }; / S(x,B) = { { B::x }, { B } }struct C:public A, public B {}; / S(x,C) = { invalid, { A in C, B in C } }struct D:publicvirtual C {}; / S(x,D) = S(x,C)struct E:publicvirtual C {char x; }; / S(x,E) = { { E::x }, { E } }struct F:public D, public E {}; / S(x,F) = S(x,E)int main(){
F f;
f.x =0; / OK, lookup finds E::x}
S(x,F) is unambiguous because the A and B base
class subobjects of D are also base class subobjects of E, so
S(x,D) is discarded in the first merge step.
If M is a non-dependent conversion-function-id,
conversion function templates that are members of T are considered.
For each such template F, the lookup set S(t,T) is constructed,
considering a function template declaration to have the name t
only if it corresponds to a declaration of F ([basic.scope.scope]).
The members of the declaration set of each such lookup set,
which shall not be an invalid set, are included in the result.
A static member, a nested type or an enumerator defined in a base class
T can unambiguously be found even if an object has more than one
base class subobject of type T.
Two base class subobjects share
the non-static member subobjects of their common virtual base classes.
— end note]
[Example 2: struct V {int v;
};
struct A {int a;
staticint s;
enum{ e };
};
struct B : A, virtual V {};
struct C : A, virtual V {};
struct D : B, C {};
void f(D* pd){
pd->v++; / OK, only one v (virtual)
pd->s++; / OK, only one s (static)int i = pd->e; / OK, only one e (enumerator)
pd->a++; / error: ambiguous: two as in D} — end example]
When virtual base classes are used, a hidden declaration can be reached
along a path through the subobject lattice that does not pass through
the hiding declaration.
The identical use with
non-virtual base classes is an ambiguity; in that case there is no
unique instance of the name that hides all the others.
— end note]
[Example 3: struct V {int f(); int x; };
struct W {int g(); int y; };
struct B :virtual V, W {int f(); int x;
int g(); int y;
};
struct C :virtual V, W {};
struct D : B, C {void glorp(); };
As illustrated in Figure 1,
the names declared in V and the left-hand instance of W
are hidden by those in B, but the names declared in the
right-hand instance of W are not hidden at all.
An explicit or implicit conversion from a pointer to or
an expression designating an object
of a
derived class to a pointer or reference to one of its base classes shall
unambiguously refer to a unique object representing the base class.
[Example 4: struct V {};
struct A {};
struct B : A, virtual V {};
struct C : A, virtual V {};
struct D : B, C {};
void g(){
D d;
B* pb =&d;
A* pa =&d; / error: ambiguous: C's A or B's A?
V* pv =&d; / OK, only one V subobject} — end example]
Even if the result of name lookup is unambiguous, use of a name found in
multiple subobjects might still be
ambiguous ([conv.mem], [expr.ref], [class.access.base]).
A using-directive is
active in a scope S at a program point P
if it precedes P and inhabits either S or
the scope of a namespace nominated by a using-directive
that is active in S at P.
for any scope U that contains P and is or is contained by S,
each namespace contained by S that is nominated by
a using-directive that is active in U at P.
If no declarations are found,
the results of the unqualified search are
the results of an unqualified search in the parent scope of S, if any,
from P.
If that lookup finds nothing, it undergoes unqualified name lookup;
in each case, only names
that denote types or templates whose specializations are types are considered.
[Example 1: struct T1 {struct U {int i; }; };
struct T2 {};
struct U1 {};
struct U2 {};
struct B {using T = T1;
using U = U1;
operator U1 T1::*();
operator U1 T2::*();
operator U2 T1::*();
operator U2 T2::*();
};
template<class X, class T>int g(){using U = U2;
X().operator U T::*(); / #1, searches for T in the scope of X first
X().operator U decltype(T()::*(); / #2return0;
}int x = g<B, T2>(); / #1 calls B::operator U1 T1::*/ #2 calls B::operator U1 T2::* — end example]
If that lookup finds nothing, it undergoes unqualified name lookup.
[Example 2: using I =int;
using D =double;
namespace A {inlinenamespace N {using C =char; }using F =float;
void f(I);
void f(D);
void f(C);
void f(F);
}struct X0 {using F =float; };
struct W {using D =void;
struct X : X0 {void g(I);
void g(::D);
void g(F);
};
};
namespace B {typedefshort I, F;
class Y {friendvoid A::f(I); / error: no void A::f(short)friendvoid A::f(D); / OKfriendvoid A::f(C); / error: A::N::C not foundfriendvoid A::f(F); / OKfriendvoid W::X::g(I); / error: no void X::g(short)friendvoid W::X::g(D); / OKfriendvoid W::X::g(F); / OK};
} — end example]
declaration not of a function or function template
then lookup for the name also includes the result of
argument-dependent lookup in a set of associated namespaces
that depends on the types of the arguments
(and for type template template arguments, the namespace of the template argument),
as specified below.
[Example 1: namespace N {struct S {};
void f(S);
}void g(){
N::S s;
f(s); / OK, calls N::f(f)(s); / error: N::f not considered; parentheses prevent argument-dependent lookup} — end example]
For example,
int h;
void g();
namespace N {struct A {};
template<class T>int f(T);
template<class T>int g(T);
template<class T>int h(T);
}int x = f<N::A>(N::A(); / OK, lookup of f finds nothing, f treated as template nameint y = g<N::A>(N::A(); / OK, lookup of g finds a function, g treated as template nameint z = h<N::A>(N::A(); / error: h< does not begin a template-id
The rules have no effect on the syntactic interpretation of an expression.
For example,
typedefint f;
namespace N {struct A {friendvoid f(A &);
operatorint();
void g(A a){int i = f(a); / f is the typedef, not the friend function: equivalent to int(a)}};
}
Because the expression is not a function call,
argument-dependent name lookup does not apply and
the friend function f is not found.
If T is std::meta::info ([meta.syn]),
its associated set of entities is the singleton containing
the enumeration type std::meta::operators ([meta.reflection.operators]).
The std::meta::info type is a type alias,
so an explicit rule is needed to associate calls
whose arguments are reflections with the namespace std::meta.
If T is a class type (including unions),
its associated entities are:
the class itself;
the class of which it is a member, if any;
and, if it is a complete type, its direct and indirect base classes.
Furthermore, if T is a class template specialization,
its associated entities also include:
the entities
associated with the types of the template arguments
provided for template type parameters;
the templates used as type template template arguments; and
the classes of which any member templates used as type template template
arguments are members.
If T is a pointer to a member function of a class
X, its associated entities are those associated
with the function parameter types and return type, together with those
associated with X.