|
445 | 445 | \ref{class.dtor}, and \ref{class.copy.assign}).
|
446 | 446 | An inline function or variable shall be defined in every
|
447 | 447 | translation unit in which it is odr-used outside of a discarded statement.
|
| 448 | +\begin{example} |
| 449 | +\begin{codeblock} |
| 450 | +auto f() { |
| 451 | + struct A {}; |
| 452 | + return A{}; |
| 453 | +} |
| 454 | +decltype(f()) g(); |
| 455 | +auto x = g(); |
| 456 | +\end{codeblock} |
| 457 | +A program containing this translation unit is ill-formed |
| 458 | +because \tcode{g} is odr-used but not defined, |
| 459 | +and cannot be defined in any other translation unit |
| 460 | +because the local class \tcode{A} cannot be named outside this |
| 461 | +translation unit. |
| 462 | +\end{example} |
448 | 463 |
|
449 | 464 | \pnum
|
450 | 465 | \indextext{type!incomplete}%
|
|
2456 | 2471 | noted, a name declared at block scope\iref{basic.scope.block} has no
|
2457 | 2472 | linkage.
|
2458 | 2473 |
|
2459 |
| -\pnum |
2460 |
| -A type is said to have linkage if and only if: |
2461 |
| -\begin{itemize} |
2462 |
| -\item it is a class or enumeration type that is named (or has a name for |
2463 |
| -linkage purposes\iref{dcl.typedef}) and the name has linkage; or |
2464 |
| - |
2465 |
| -\item it is an unnamed class or unnamed enumeration that is a member of a class |
2466 |
| -with linkage; or |
2467 |
| - |
2468 |
| -\item it is a specialization of a class template\iref{temp}\footnote{A class |
2469 |
| -template has the linkage of the innermost enclosing class or namespace in which |
2470 |
| -it is declared.}; |
2471 |
| -or |
2472 |
| - |
2473 |
| -\item it is a fundamental type\iref{basic.fundamental}; or |
2474 |
| - |
2475 |
| -\item it is a compound type\iref{basic.compound} other than a class or |
2476 |
| -enumeration, compounded exclusively from types that have linkage; or |
2477 |
| - |
2478 |
| -\item it is a cv-qualified\iref{basic.type.qualifier} version of a |
2479 |
| -type that has linkage. |
2480 |
| -\end{itemize} |
2481 |
| -\begin{note} |
2482 |
| -In other words, a type without linkage contains a class or enumeration that |
2483 |
| -cannot be named outside its translation unit. |
2484 |
| -Classes with linkage may contain members |
2485 |
| -whose types do not have linkage. |
2486 |
| -Typedef names are ignored in the determination |
2487 |
| -of whether a type has linkage. |
2488 |
| -\end{note} |
2489 |
| - |
2490 |
| -\begin{example} |
2491 |
| -\begin{codeblock} |
2492 |
| -template <class T> struct B { |
2493 |
| - void g(T) { } |
2494 |
| - void h(T); |
2495 |
| - friend void i(B, T) { } |
2496 |
| -}; |
2497 |
| - |
2498 |
| -void f() { |
2499 |
| - struct A { int x; }; // no linkage |
2500 |
| - A a = { 1 }; |
2501 |
| - B<A> ba; // declares \tcode{B<A>::g(A)} and \tcode{B<A>::h(A)} |
2502 |
| - ba.g(a); // OK |
2503 |
| - ba.h(a); // error: \tcode{B<A>::h(A)} not defined; \tcode{A} cannot be named in another translation unit |
2504 |
| - i(ba, a); // OK |
2505 |
| -} |
2506 |
| -\end{codeblock} |
2507 |
| -\end{example} |
2508 |
| - |
2509 | 2474 | \pnum
|
2510 | 2475 | Two names that are the same\iref{basic} and that are declared
|
2511 | 2476 | in different scopes shall denote the same variable, function,
|
|
0 commit comments