Skip to content

Commit f6db1de

Browse files
committed
basic.lookup.general
1 parent 5d45ce9 commit f6db1de

File tree

1 file changed

+78
-16
lines changed

1 file changed

+78
-16
lines changed

source/basic.tex

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,9 +1336,10 @@
13361336

13371337
\rSec1[basic.lookup]{Name lookup}%
13381338

1339+
\indextext{lookup!name|(}
1340+
13391341
\rSec2[basic.lookup.general]{General}%
1340-
\indextext{scope!name lookup and|(}%
1341-
\indextext{lookup!name|(}%
1342+
\indextext{scope!name lookup and|see{lookup, name}}%
13421343

13431344
\pnum
13441345
The name lookup rules apply uniformly to all names (including
@@ -1348,36 +1349,98 @@
13481349
such names in the context discussed by a particular rule. Name lookup
13491350
associates the use of a name with a set of declarations\iref{basic.def} of
13501351
that name.
1352+
Unless otherwise specified,
1353+
the program is ill-formed if no declarations are found.
13511354
If the declarations found by name lookup
13521355
all denote functions or function templates,
13531356
the declarations are said to form an \defn{overload set}.
1354-
The declarations found by name lookup shall either
1355-
all denote the same entity or form an overload set.
1357+
Otherwise,
1358+
if the declarations found by name lookup do not all denote the same entity,
1359+
they are \defn{ambiguous} and the program is ill-formed.
13561360
Overload resolution~(\ref{over.match}, \ref{over.over})
13571361
takes place after name lookup has succeeded. The access rules\iref{class.access}
13581362
are considered only once name lookup and
13591363
function overload resolution (if applicable) have succeeded. Only after
13601364
name lookup, function overload resolution (if applicable) and access
13611365
checking have succeeded
1362-
are the semantic properties introduced by the name's declaration
1363-
and its reachable\iref{module.reach} redeclarations
1364-
used further in expression processing\iref{expr}.
1366+
are the semantic properties introduced by the declarations
1367+
used in further processing.
13651368

13661369
\pnum
1367-
A name ``looked up in the context of an expression'' is looked up
1368-
in the scope where the expression is found.
1370+
A program point $P$ is said to follow
1371+
any declaration in the same translation unit
1372+
whose locus\iref{basic.scope.pdecl} is before $P$.
1373+
\begin{note}
1374+
The declaration might appear in a scope that does not contain $P$.
1375+
\end{note}
1376+
A declaration $X$ \defnx{precedes}{precede}
1377+
a program point $P$ in a translation unit $L$
1378+
if $P$ follows $X$, $X$ inhabits a class scope and is reachable from $P$, or
1379+
else $X$ appears in a translation unit $D$ and
1380+
\begin{itemize}
1381+
\item
1382+
$P$ follows
1383+
a \grammarterm{module-import-declaration} or \grammarterm{module-declaration}
1384+
that imports $D$ (directly or indirectly), and
1385+
\item
1386+
$X$ appears after the \grammarterm{module-declaration} in $D$ (if any) and
1387+
before the \grammarterm{private-module-fragment} in $D$ (if any), and
1388+
\item
1389+
either $X$ is exported or else $D$ and $L$ are part of the same module and
1390+
$X$ does not inhabit a namespace with internal linkage or
1391+
declare a name with internal linkage.
1392+
\begin{note}
1393+
Names declared by a \grammarterm{using-declaration} have no linkage.
1394+
\end{note}
1395+
\end{itemize}
1396+
\begin{note}
1397+
A \grammarterm{module-import-declaration} imports both
1398+
the named translation unit(s) and
1399+
any modules named by exported
1400+
\grammarterm{module-import-declaration}{s} within them,
1401+
recursively.
1402+
\begin{example}
1403+
\begin{codeblocktu}{Translation unit \#1}
1404+
export module Q;
1405+
export int sq(int i) { return i*i; }
1406+
\end{codeblocktu}
1407+
1408+
\begin{codeblocktu}{Translation unit \#2}
1409+
export module R;
1410+
export import Q;
1411+
\end{codeblocktu}
1412+
1413+
\begin{codeblocktu}{Translation unit \#3}
1414+
import R;
1415+
int main() { return sq(9); } // OK: \tcode{sq} from module \tcode{Q}
1416+
\end{codeblocktu}
1417+
\end{example}
1418+
\end{note}
13691419

13701420
\pnum
1371-
The injected-class-name of a class\iref{class.pre} is also
1372-
considered to be a member of that class for the purposes of name hiding
1373-
and lookup.
1421+
A \defnadj{single}{search} in a scope $S$
1422+
for a name $N$ from a program point $P$
1423+
finds all declarations that precede $P$
1424+
to which any name that is the same as $N$\iref{basic.pre} is bound in $S$.
1425+
If any such declaration is a \grammarterm{using-declarator}
1426+
whose terminal name\iref{expr.prim.id.unqual}
1427+
is not dependent\iref{temp.dep.type},
1428+
it is replaced by the declarations named by
1429+
the \grammarterm{using-declarator}\iref{namespace.udecl}.
13741430

13751431
\pnum
1432+
In certain contexts, only certain kinds of declarations are included.
1433+
After any such restriction, any declarations of classes or enumerations are discarded if any other declarations are found.
13761434
\begin{note}
1377-
\ref{basic.link} discusses linkage issues. The notions of
1378-
scope, point of declaration and name hiding are discussed
1379-
in~\ref{basic.scope}.
1435+
A type (but not a \grammarterm{typedef-name} or template)
1436+
is therefore hidden by any other entity in its scope.
13801437
\end{note}
1438+
However, if a lookup is type-only, only declarations of types and
1439+
templates whose specializations are types are considered;
1440+
furthermore, if declarations
1441+
of a \grammarterm{typedef-name} and of the type to which it refers are found,
1442+
the declaration of the \grammarterm{typedef-name} is discarded
1443+
instead of the type declaration.
13811444

13821445
\rSec2[basic.lookup.unqual]{Unqualified name lookup}
13831446

@@ -2593,7 +2656,6 @@
25932656
\grammarterm{nested-name-specifier}{}
25942657
only namespace names are considered.%
25952658
\indextext{lookup!name|)}%
2596-
\indextext{scope!name lookup and|)}
25972659

25982660
\rSec1[basic.link]{Program and linkage}%
25992661
\indextext{linkage|(}

0 commit comments

Comments
 (0)