|
1336 | 1336 |
|
1337 | 1337 | \rSec1[basic.lookup]{Name lookup}%
|
1338 | 1338 |
|
| 1339 | +\indextext{lookup!name|(} |
| 1340 | + |
1339 | 1341 | \rSec2[basic.lookup.general]{General}%
|
1340 |
| -\indextext{scope!name lookup and|(}% |
1341 |
| -\indextext{lookup!name|(}% |
| 1342 | +\indextext{scope!name lookup and|see{lookup, name}}% |
1342 | 1343 |
|
1343 | 1344 | \pnum
|
1344 | 1345 | The name lookup rules apply uniformly to all names (including
|
|
1348 | 1349 | such names in the context discussed by a particular rule. Name lookup
|
1349 | 1350 | associates the use of a name with a set of declarations\iref{basic.def} of
|
1350 | 1351 | that name.
|
| 1352 | +Unless otherwise specified, |
| 1353 | +the program is ill-formed if no declarations are found. |
1351 | 1354 | If the declarations found by name lookup
|
1352 | 1355 | all denote functions or function templates,
|
1353 | 1356 | 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. |
1356 | 1360 | Overload resolution~(\ref{over.match}, \ref{over.over})
|
1357 | 1361 | takes place after name lookup has succeeded. The access rules\iref{class.access}
|
1358 | 1362 | are considered only once name lookup and
|
1359 | 1363 | function overload resolution (if applicable) have succeeded. Only after
|
1360 | 1364 | name lookup, function overload resolution (if applicable) and access
|
1361 | 1365 | 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. |
1365 | 1368 |
|
1366 | 1369 | \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} |
1369 | 1419 |
|
1370 | 1420 | \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}. |
1374 | 1430 |
|
1375 | 1431 | \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. |
1376 | 1434 | \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. |
1380 | 1437 | \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. |
1381 | 1444 |
|
1382 | 1445 | \rSec2[basic.lookup.unqual]{Unqualified name lookup}
|
1383 | 1446 |
|
|
2593 | 2656 | \grammarterm{nested-name-specifier}{}
|
2594 | 2657 | only namespace names are considered.%
|
2595 | 2658 | \indextext{lookup!name|)}%
|
2596 |
| -\indextext{scope!name lookup and|)} |
2597 | 2659 |
|
2598 | 2660 | \rSec1[basic.link]{Program and linkage}%
|
2599 | 2661 | \indextext{linkage|(}
|
|
0 commit comments