|
279 | 279 |
|
280 | 280 | \pnum
|
281 | 281 | \indextext{expression!potentially evaluated}%
|
282 |
| -An expression is \defn{potentially evaluated} unless it is an |
283 |
| -unevaluated operand\iref{expr.prop} or a subexpression thereof. |
| 282 | +An expression or conversion is \defn{potentially evaluated} unless it is |
| 283 | +an unevaluated operand\iref{expr.prop}, |
| 284 | +a subexpression thereof, or |
| 285 | +a conversion in an initialization or conversion sequence in such a context. |
284 | 286 | The set of \defn{potential results} of an expression \tcode{e} is
|
285 | 287 | defined as follows:
|
286 | 288 | \begin{itemize}
|
|
290 | 292 | \item If \tcode{e} is a subscripting operation\iref{expr.sub} with
|
291 | 293 | an array operand, the set contains the potential results of that operand.
|
292 | 294 | \item If \tcode{e} is a class member access
|
293 |
| -expression\iref{expr.ref}, the set contains the potential results of |
294 |
| -the object expression. |
| 295 | +expression\iref{expr.ref} of the form |
| 296 | +\tcode{e1 . \opt{template} e2} |
| 297 | +naming a non-static data member, |
| 298 | +the set contains the potential results of \tcode{e1}. |
| 299 | +\item if \tcode{e} is a class member access expression |
| 300 | +naming a static data member, |
| 301 | +the set contains the \grammarterm{id-expression} designating the data member. |
295 | 302 | \item If \tcode{e} is a pointer-to-member
|
296 |
| -expression\iref{expr.mptr.oper} whose second operand is a constant |
297 |
| -expression, the set contains the potential results of the object |
298 |
| -expression. |
| 303 | +expression\iref{expr.mptr.oper} of the form |
| 304 | +\tcode{e1 .* e2}, |
| 305 | +the set contains the potential results of \tcode{e1}. |
299 | 306 | \item If \tcode{e} has the form \tcode{(e1)}, the set contains the
|
300 | 307 | potential results of \tcode{e1}.
|
301 | 308 | \item If \tcode{e} is a glvalue conditional
|
|
322 | 329 | \end{note}
|
323 | 330 |
|
324 | 331 | \pnum
|
325 |
| -\indextext{function!named by an expression}% |
326 |
| -A function is \defn{named by an expression} as follows: |
| 332 | +A function is \defnx{named by}{function!named by expression or conversion} |
| 333 | +an expression or conversion as follows: |
327 | 334 | \begin{itemize}
|
328 | 335 | \item
|
329 |
| - A function whose name appears in an expression |
330 |
| - is named by that expression |
331 |
| - if it is the unique lookup result or the selected member |
332 |
| - of a set of overloaded functions~(\ref{basic.lookup}, \ref{over.match}, \ref{over.over}), |
| 336 | + A function is named by an expression or conversion |
| 337 | + if it is the unique result of a name lookup or the selected member |
| 338 | + of a set of overloaded functions~(\ref{basic.lookup}, \ref{over.match}, \ref{over.over}) |
| 339 | + in an overload resolution performed |
| 340 | + as part of forming that expression or conversion, |
333 | 341 | unless it is a pure virtual function and either
|
334 |
| - its name is not explicitly qualified or |
| 342 | + the expression is not an \grammarterm{id-expression} naming the function with |
| 343 | + an explicitly qualified name or |
335 | 344 | the expression forms a pointer to member\iref{expr.unary.op}.
|
336 | 345 | \begin{note} This covers
|
337 | 346 | taking the address of functions~(\ref{conv.func}, \ref{expr.unary.op}),
|
338 | 347 | calls to named functions\iref{expr.call},
|
339 | 348 | operator overloading\iref{over},
|
340 | 349 | user-defined conversions\iref{class.conv.fct},
|
341 |
| - allocation functions for placement \grammarterm{new-expression}{s}\iref{expr.new}, as well as |
| 350 | + allocation functions for \grammarterm{new-expression}{s}\iref{expr.new}, as well as |
342 | 351 | non-default initialization\iref{dcl.init}.
|
343 | 352 | A constructor selected to copy or move an object of class type
|
344 |
| - is considered to be named by an expression |
| 353 | + is considered to be named by an expression or conversion |
345 | 354 | even if the call is actually elided by the implementation\iref{class.copy.elision}. \end{note}
|
346 | 355 | \item
|
347 |
| - An allocation or deallocation function for a class |
| 356 | + A deallocation function for a class |
348 | 357 | is named by a \grammarterm{new-expression}
|
349 |
| - as specified in~\ref{expr.new} and~\ref{class.free}. |
| 358 | + if it is the single matching deallocation function |
| 359 | + for the allocation function selected by overload resolution, |
| 360 | + as specified in~\ref{expr.new}. |
350 | 361 | \item
|
351 | 362 | A deallocation function for a class
|
352 |
| - is named by a delete expression |
| 363 | + is named by a \grammarterm{delete-expression} |
| 364 | + if it is the selected usual deallocation function |
353 | 365 | as specified in~\ref{expr.delete} and~\ref{class.free}.
|
354 | 366 | \end{itemize}
|
355 | 367 |
|
356 | 368 | \pnum
|
357 | 369 | A variable \tcode{x} whose name appears as a
|
358 |
| -potentially-evaluated expression \tcode{ex} is \defnx{odr-used}{odr-use} by \tcode{ex} unless |
359 |
| -applying the lvalue-to-rvalue conversion\iref{conv.lval} to \tcode{x} yields |
360 |
| -a constant expression\iref{expr.const} |
361 |
| -that does not invoke a function |
362 |
| -other than a trivial special member function\iref{special} |
363 |
| -and, if \tcode{x} is an object, \tcode{ex} is an element of |
364 |
| -the set of potential results of an expression \tcode{e}, where either the lvalue-to-rvalue |
365 |
| -conversion\iref{conv.lval} is applied to \tcode{e}, or \tcode{e} is |
366 |
| -a discarded-value expression\iref{expr.prop}. |
| 370 | +potentially-evaluated expression \tcode{e} |
| 371 | +is \defnx{odr-used}{odr-use} by \tcode{e} unless |
| 372 | +\begin{itemize} |
| 373 | +\item |
| 374 | + \tcode{x} is a reference that is |
| 375 | + usable in constant expressions\iref{expr.const}, or |
| 376 | +\item |
| 377 | + \tcode{x} is a variable of non-reference type that is |
| 378 | + usable in constant expressions and has no mutable subobjects, and |
| 379 | + \tcode{e} is an element of the set of potential results of an expression |
| 380 | + of non-volatile-qualified non-class type |
| 381 | + to which the lvalue-to-rvalue conversion\iref{conv.lval} is applied, or |
| 382 | +\item |
| 383 | + \tcode{x} is a variable of non-reference type, and |
| 384 | + \tcode{e} is an element of the set of potential results |
| 385 | + of a discarded-value expression\iref{expr.prop} |
| 386 | + to which the lvalue-to-rvalue conversion is not applied. |
| 387 | +\end{itemize} |
367 | 388 |
|
368 | 389 | \pnum
|
369 | 390 | A structured binding is odr-used if it appears as a potentially-evaluated expression.
|
|
376 | 397 | \pnum
|
377 | 398 | A virtual member
|
378 | 399 | function is odr-used if it is not pure.
|
379 |
| -A function is odr-used if it is named by a potentially-evaluated expression. |
| 400 | +A function is odr-used if it is named by |
| 401 | +a potentially-evaluated expression or conversion. |
380 | 402 | A non-placement allocation or deallocation
|
381 | 403 | function for a class is odr-used by the definition of a constructor of that
|
382 | 404 | class. A non-placement deallocation function for a class is odr-used by the
|
|
415 | 437 | \begin{itemize}
|
416 | 438 | \item the intervening declarative region is a block scope, or
|
417 | 439 | \item the intervening declarative region is the function parameter scope of a \grammarterm{lambda-expression}
|
418 |
| -that has a \grammarterm{simple-capture} naming the entity or has a \grammarterm{capture-default}. |
| 440 | +that has a \grammarterm{simple-capture} |
| 441 | +naming the entity or has a \grammarterm{capture-default}, and |
| 442 | +the block scope of the \grammarterm{lambda-expression} |
| 443 | +is also an intervening declarative region. |
419 | 444 | \end{itemize}
|
420 | 445 | \end{itemize}
|
421 | 446 |
|
|
425 | 450 | \begin{example}
|
426 | 451 | \begin{codeblock}
|
427 | 452 | void f(int n) {
|
428 |
| - [] { n = 1; }; // error, \tcode{n} is not odr-usable due to intervening lambda-expression |
| 453 | + [] { n = 1; }; // error: \tcode{n} is not odr-usable due to intervening lambda-expression |
429 | 454 | struct A {
|
430 |
| - void f() { n = 2; } // error, \tcode{n} is not odr-usable due to intervening function definition scope |
| 455 | + void f() { n = 2; } // error: \tcode{n} is not odr-usable due to intervening function definition scope |
431 | 456 | };
|
432 |
| - void g(int = n); // error, \tcode{n} is not odr-usable due to intervening function parameter scope |
| 457 | + void g(int = n); // error: \tcode{n} is not odr-usable due to intervening function parameter scope |
| 458 | + [=](int k = n) {}; // error: \tcode{n} is not odr-usable due to being |
| 459 | + // outside the block scope of the \grammarterm{lambda-expression} |
433 | 460 | [&] { [n]{ return n; }; }; // OK
|
434 | 461 | }
|
435 | 462 | \end{codeblock}
|
|
696 | 723 | all refer to the same variable, non-static data member, or enumerator,
|
697 | 724 | or all refer to functions and function templates;
|
698 | 725 | in this case the class name or enumeration name is
|
699 |
| -hidden\iref{basic.scope.hiding}. \begin{note} A namespace name or a |
700 |
| -class template name must be unique in its declarative |
701 |
| -region~(\ref{namespace.alias}, \ref{temp}). \end{note} |
| 726 | +hidden\iref{basic.scope.hiding}. |
| 727 | +\begin{note} |
| 728 | +A structured binding\iref{dcl.struct.bind}, |
| 729 | +namespace name\iref{basic.namespace}, or |
| 730 | +class template name\iref{temp} |
| 731 | +must be unique in its declarative region. |
| 732 | +\end{note} |
702 | 733 | \end{itemize}
|
703 | 734 | \begin{note} These restrictions apply to the declarative region into which
|
704 | 735 | a name is introduced, which is not necessarily the same as the region in
|
|
2373 | 2404 | linkage if it is the name of
|
2374 | 2405 | \begin{itemize}
|
2375 | 2406 | \item
|
2376 |
| - a variable, function or function template that is |
| 2407 | + a variable, variable template, function, or function template that is |
2377 | 2408 | explicitly declared \tcode{static}; or,
|
2378 | 2409 | \item
|
2379 |
| - a non-inline variable of non-volatile const-qualified type that is |
| 2410 | + a non-inline non-template variable of non-volatile const-qualified type |
| 2411 | + that is |
2380 | 2412 | neither explicitly declared \tcode{extern} nor previously
|
2381 | 2413 | declared to have external linkage; or
|
2382 | 2414 | \item
|
2383 | 2415 | a data member of an anonymous union.
|
2384 | 2416 | \end{itemize}
|
| 2417 | +\begin{note} |
| 2418 | +An instantiated variable template that has const-qualified type |
| 2419 | +can have external linkage, even if not declared \tcode{extern}. |
| 2420 | +\end{note} |
2385 | 2421 |
|
2386 | 2422 | \pnum
|
2387 | 2423 | An unnamed namespace or a namespace declared directly or indirectly within an
|
|
2414 | 2450 | \pnum
|
2415 | 2451 | The name of a function declared in block scope and the name of a variable declared by a
|
2416 | 2452 | block scope \tcode{extern} declaration have linkage. If there is a visible declaration
|
2417 |
| -of an entity with linkage having the same name and type, ignoring entities declared |
2418 |
| -outside the innermost enclosing namespace scope, the block scope declaration declares |
| 2453 | +of an entity with linkage, ignoring entities declared |
| 2454 | +outside the innermost enclosing namespace scope, |
| 2455 | +such that the block scope declaration would be |
| 2456 | +a (possibly ill-formed) redeclaration |
| 2457 | +if the two declarations appeared in the same declarative region, |
| 2458 | +the block scope declaration declares |
2419 | 2459 | that same entity and receives the linkage of the previous declaration. If there is more
|
2420 | 2460 | than one such matching entity, the program is ill-formed. Otherwise, if no matching
|
2421 | 2461 | entity is found, the block scope entity receives external linkage.
|
|
2424 | 2464 | \begin{example}
|
2425 | 2465 | \begin{codeblock}
|
2426 | 2466 | static void f();
|
| 2467 | +extern "C" void h(); |
2427 | 2468 | static int i = 0; // \#1
|
2428 | 2469 | void g() {
|
2429 | 2470 | extern void f(); // internal linkage
|
| 2471 | + extern void h(); // C language linkage |
2430 | 2472 | int i; // \#2: \tcode{i} has no linkage
|
2431 | 2473 | {
|
2432 | 2474 | extern void f(); // internal linkage
|
|
0 commit comments