[basic.lookup.general]

# 6 Basics [[basic]](./#basic)

## 6.5 Name lookup [[basic.lookup]](basic.lookup#general)

### 6.5.1 General [basic.lookup.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1624)

[*Name lookup*](#def:lookup,name "6.5.1 General [basic.lookup.general]") associates the use of a name
with a set of declarations ([[basic.def]](basic.def "6.2 Declarations and definitions")) of that name[.](#1.sentence-1)

The name lookup rules apply uniformly to all names (including[*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]")*s* ([[dcl.typedef]](dcl.typedef "9.2.4 The typedef specifier")),[*namespace-name*](namespace.def.general#nt:namespace-name "9.9.2.1 General [namespace.def.general]")*s* ([[basic.namespace]](basic.namespace "9.9 Namespaces")), and[*class-name*](class.pre#nt:class-name "11.1 Preamble [class.pre]")*s* ([[class.name]](class.name "11.3 Class names"))) wherever the grammar allows
such names in the context discussed by a particular rule[.](#1.sentence-2)

Unless otherwise specified,
the program is ill-formed if no declarations are found[.](#1.sentence-3)

If the declarations found by name lookup
all denote functions or function templates,
the declarations are said to form an [*overload set*](#def:overload_set "6.5.1 General [basic.lookup.general]")[.](#1.sentence-4)

Otherwise,
if the declarations found by name lookup do not all denote the same entity,they are [*ambiguous*](#def:ambiguous "6.5.1 General [basic.lookup.general]") and the program is ill-formed[.](#1.sentence-5)

Overload resolution ([[over.match]](over.match "12.2 Overload resolution"), [[over.over]](over.over "12.3 Address of an overload set"))
takes place after name lookup has succeeded[.](#1.sentence-6)

The access rules ([[class.access]](class.access "11.8 Member access control"))
are considered only once name lookup and
function overload resolution (if applicable) have succeeded[.](#1.sentence-7)

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[.](#1.sentence-8)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1650)

A program point P is said to follow
any declaration in the same translation unit
whose locus ([[basic.scope.pdecl]](basic.scope.pdecl "6.4.2 Point of declaration")) is before P[.](#2.sentence-1)

[*Note [1](#note-1)*:

The declaration might appear in a scope that does not contain P[.](#2.sentence-2)

â *end note*]

A declaration X [*precedes*](#def:declaration,precede "6.5.1 General [basic.lookup.general]") 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

- [(2.1)](#2.1)

P follows
a [*module-import-declaration*](module.import#nt:module-import-declaration "10.3 Import declaration [module.import]") or [*module-declaration*](module.unit#nt:module-declaration "10.1 Module units and purviews [module.unit]") that imports D (directly or indirectly), and

- [(2.2)](#2.2)

X appears after the [*module-declaration*](module.unit#nt:module-declaration "10.1 Module units and purviews [module.unit]") in D (if any) and
before the [*private-module-fragment*](module.private.frag#nt:private-module-fragment "10.5 Private module fragment [module.private.frag]") in D (if any), and

- [(2.3)](#2.3)

either X is exported or else D and L are part of the same module andX does not inhabit a namespace with internal linkage or
declare a name with internal linkage[.](#2.sentence-3)
  [*Note [2](#note-2)*:
  Names declared by a [*using-declaration*](namespace.udecl#nt:using-declaration "9.10 The using declaration [namespace.udecl]") have no linkage[.](#2.3.sentence-2)
 â *end note*]

[*Note [3](#note-3)*:

A [*module-import-declaration*](module.import#nt:module-import-declaration "10.3 Import declaration [module.import]") imports both
the named translation unit(s) and
any modules named by exported[*module-import-declaration*](module.import#nt:module-import-declaration "10.3 Import declaration [module.import]")*s* within them,
recursively[.](#2.sentence-4)

[*Example [1](#example-1)*:

Translation unit #1:export module Q;export int sq(int i) { return i*i; }

Translation unit #2:export module R;export import Q;

Translation unit #3:import R;int main() { return sq(9); } // OK, sq from module Q â *end example*]

â *end note*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1702)

A [*single search*](#def:search,single "6.5.1 General [basic.lookup.general]") 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]](basic.pre "6.1 Preamble")) is bound in S[.](#3.sentence-1)

If any such declaration is a [*using-declarator*](namespace.udecl#nt:using-declarator "9.10 The using declaration [namespace.udecl]") whose terminal name ([[expr.prim.id.unqual]](expr.prim.id.unqual "7.5.5.2 Unqualified names"))
is not dependent ([[temp.dep.type]](temp.dep.type "13.8.3.2 Dependent types")),
it is replaced by the declarations named by
the [*using-declarator*](namespace.udecl#nt:using-declarator "9.10 The using declaration [namespace.udecl]") ([[namespace.udecl]](namespace.udecl "9.10 The using declaration"))[.](#3.sentence-2)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L1714)

In certain contexts, only certain kinds of declarations are included[.](#4.sentence-1)

After any such restriction, any declarations of classes or enumerations are discarded if any other declarations are found[.](#4.sentence-2)

[*Note [4](#note-4)*:

A type (but not a type alias or template)
is therefore hidden by any other entity in its scope[.](#4.sentence-3)

â *end note*]

However, if a lookup is [*type-only*](#def:lookup,type-only "6.5.1 General [basic.lookup.general]"),
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[.](#4.sentence-4)
