|
465 | 465 |
|
466 | 466 | \pnum
|
467 | 467 | \tcode{*\keyword{this}} is odr-used if \keyword{this} appears as a potentially-evaluated expression
|
468 |
| -(including as the result of the implicit transformation in the body of a non-static |
469 |
| -member function\iref{class.mfct.non.static}). |
| 468 | +(including as the result of any implicit transformation to |
| 469 | +a class member access expression\iref{expr.prim.id.general}). |
470 | 470 |
|
471 | 471 | \pnum
|
472 | 472 | A virtual member
|
|
537 | 537 | \end{codeblock}
|
538 | 538 | \end{example}
|
539 | 539 |
|
| 540 | +\pnum |
| 541 | +\begin{example} |
| 542 | +\begin{codeblock} |
| 543 | +void g() { |
| 544 | + constexpr int x = 1; |
| 545 | + auto lambda = [] <typename T, int = ((T)x, 0)> {}; // OK |
| 546 | + lambda.operator()<int, 1>(); // OK, does not consider \tcode{x} at all |
| 547 | + lambda.operator()<int>(); // OK, does not odr-use \tcode{x} |
| 548 | + lambda.operator()<const int&>(); // error: odr-uses \tcode{x} from a context where \tcode{x} is not odr-usable |
| 549 | +} |
| 550 | + |
| 551 | +void h() { |
| 552 | + constexpr int x = 1; |
| 553 | + auto lambda = [] <typename T> { (T)x; }; // OK |
| 554 | + lambda.operator()<int>(); // OK, does not odr-use \tcode{x} |
| 555 | + lambda.operator()<void>(); // OK, does not odr-use \tcode{x} |
| 556 | + lambda.operator()<const int&>(); // error: odr-uses \tcode{x} from a context where \tcode{x} is not odr-usable |
| 557 | +} |
| 558 | +\end{codeblock} |
| 559 | +\end{example} |
| 560 | + |
540 | 561 | \pnum
|
541 | 562 | Every program shall contain at least one definition of every
|
542 | 563 | function or variable that is odr-used in that program
|
|
2034 | 2055 | its associated entities are:
|
2035 | 2056 | the class itself;
|
2036 | 2057 | the class of which it is a member, if any;
|
2037 |
| -and its direct and indirect base classes. |
| 2058 | +and, if it is a complete type, its direct and indirect base classes. |
2038 | 2059 | Furthermore, if \tcode{T} is a class template specialization,
|
2039 | 2060 | its associated entities also include:
|
2040 | 2061 | the entities
|
|
3809 | 3830 | \item automatic storage duration
|
3810 | 3831 | \item dynamic storage duration
|
3811 | 3832 | \end{itemize}
|
| 3833 | +\begin{note} |
| 3834 | +After the duration of a region of storage has ended, |
| 3835 | +the use of pointers to that region of storage is limited\iref{basic.compound}. |
| 3836 | +\end{note} |
3812 | 3837 |
|
3813 | 3838 | \pnum
|
3814 | 3839 | \indextext{storage duration!static}%
|
3815 | 3840 | \indextext{storage duration!thread}%
|
3816 | 3841 | \indextext{storage duration!automatic}%
|
3817 | 3842 | \indextext{storage duration!dynamic}%
|
3818 | 3843 | Static, thread, and automatic storage durations are associated with objects
|
3819 |
| -introduced by declarations\iref{basic.def} and implicitly created by |
3820 |
| -the implementation\iref{class.temporary}. The dynamic storage duration |
| 3844 | +introduced by declarations\iref{basic.def} and |
| 3845 | +with temporary objects\iref{class.temporary}. |
| 3846 | +The dynamic storage duration |
3821 | 3847 | is associated with objects created by a
|
3822 |
| -\grammarterm{new-expression}\iref{expr.new}. |
| 3848 | +\grammarterm{new-expression}\iref{expr.new} or |
| 3849 | +with implicitly created objects\iref{intro.object}. |
3823 | 3850 |
|
3824 | 3851 | \pnum
|
3825 | 3852 | The storage duration categories apply to references as well.
|
3826 | 3853 |
|
3827 |
| -\pnum |
3828 |
| -When the end of the duration of a region of storage is reached, |
3829 |
| -the values of all pointers |
3830 |
| -representing the address of any part of that region of storage |
3831 |
| -become invalid pointer values\iref{basic.compound}. |
3832 |
| -Indirection through an invalid pointer value and |
3833 |
| -passing an invalid pointer value to a deallocation function |
3834 |
| -have undefined behavior. |
3835 |
| -Any other use of an invalid pointer value has |
3836 |
| -\impldef{any use of an invalid pointer other than to perform indirection or deallocate} |
3837 |
| -behavior. |
3838 |
| -\begin{footnote} |
3839 |
| -Some implementations might define that |
3840 |
| -copying an invalid pointer value |
3841 |
| -causes a system-generated runtime fault. |
3842 |
| -\end{footnote} |
3843 |
| - |
3844 | 3854 | \rSec3[basic.stc.static]{Static storage duration}
|
3845 | 3855 |
|
3846 | 3856 | \pnum
|
|
3897 | 3907 |
|
3898 | 3908 | \pnum
|
3899 | 3909 | \indextext{storage duration!local object}%
|
3900 |
| -Variables that belong to a block or parameter scope and are |
| 3910 | +Variables that belong to a block scope and are |
3901 | 3911 | not explicitly declared \keyword{static}, \keyword{thread_local}, or \keyword{extern} have
|
3902 | 3912 | \defnadj{automatic}{storage duration}. The storage
|
3903 |
| -for these entities lasts until the block in which they are created exits. |
3904 |
| - |
3905 |
| -\pnum |
| 3913 | +for such variables lasts until the block in which they are created exits. |
3906 | 3914 | \begin{note}
|
3907 | 3915 | These variables are initialized and destroyed as described in~\ref{stmt.dcl}.
|
3908 | 3916 | \end{note}
|
| 3917 | +Variables that belong to a parameter scope also have automatic storage duration. |
| 3918 | +The storage for a function parameter lasts until |
| 3919 | +immediately after its destruction\iref{expr.call}. |
3909 | 3920 |
|
3910 | 3921 | \pnum
|
3911 | 3922 | If a variable with automatic storage duration has initialization or a destructor with side
|
|
4285 | 4296 | Temporary objects are created
|
4286 | 4297 | \begin{itemize}
|
4287 | 4298 | \item
|
4288 |
| -when a prvalue is converted to an xvalue\iref{conv.rval}, |
| 4299 | +when a prvalue is converted to an xvalue\iref{conv.rval} and |
4289 | 4300 | \item
|
4290 |
| -when needed by the implementation to pass or return an object of trivially copyable type (see below), |
4291 |
| -and |
4292 |
| -\item |
4293 |
| -when throwing an exception\iref{except.throw}. |
4294 |
| -\begin{note} |
4295 |
| -The lifetime of exception objects is described in~\ref{except.throw}. |
4296 |
| -\end{note} |
| 4301 | +when needed by the implementation to pass or return an object of trivially copyable type (see below). |
4297 | 4302 | \end{itemize}
|
4298 | 4303 | Even when the creation of the temporary object is
|
4299 | 4304 | unevaluated\iref{expr.context},
|
|
4318 | 4323 | when binding a reference to a prvalue\iref{dcl.init.ref,expr.type.conv,
|
4319 | 4324 | expr.dynamic.cast,expr.static.cast,expr.const.cast,expr.cast},
|
4320 | 4325 | \item
|
4321 |
| -when performing member access on a class prvalue\iref{expr.ref,expr.mptr.oper}, |
| 4326 | +when performing certain member accesses on a class prvalue\iref{expr.ref,expr.mptr.oper}, |
| 4327 | +\item |
| 4328 | +when invoking an implicit object member function on a class prvalue\iref{expr.call}, |
4322 | 4329 | \item
|
4323 | 4330 | when performing an array-to-pointer conversion or subscripting on an array prvalue\iref{conv.array,expr.sub},
|
4324 | 4331 | \item
|
|
4541 | 4548 | \end{itemize}
|
4542 | 4549 |
|
4543 | 4550 | \pnum
|
4544 |
| -The fourth context is when a temporary object other than a function parameter object |
| 4551 | +The fourth context is when a temporary object |
4545 | 4552 | is created in the \grammarterm{for-range-initializer} of a range-based \keyword{for} statement.
|
4546 | 4553 | If such a temporary object would otherwise be destroyed
|
4547 | 4554 | at the end of the \grammarterm{for-range-initializer} full-expression,
|
4548 | 4555 | the object persists for the lifetime of the reference
|
4549 | 4556 | initialized by the \grammarterm{for-range-initializer}.
|
4550 | 4557 |
|
4551 | 4558 | \pnum
|
4552 |
| -The destruction of a temporary whose lifetime is not extended |
4553 |
| -beyond the full-expression in which it was created |
4554 |
| -is sequenced before the destruction of every |
4555 |
| -temporary which is constructed earlier in the same full-expression. |
| 4559 | +Let \tcode{x} and \tcode{y} each be either |
| 4560 | +a temporary object whose lifetime is not extended, or |
| 4561 | +a function parameter. |
| 4562 | +If the lifetimes of \tcode{x} and \tcode{y} end at |
| 4563 | +the end of the same full-expression, and |
| 4564 | +\tcode{x} is initialized before \tcode{y}, then |
| 4565 | +the destruction of \tcode{y} is sequenced before that of \tcode{x}. |
4556 | 4566 | If the lifetime of two or more temporaries
|
4557 | 4567 | with lifetimes extending beyond the full-expressions in which they were created
|
4558 | 4568 | ends at the same point,
|
|
5207 | 5217 | to type \cv{}~\keyword{void}.
|
5208 | 5218 |
|
5209 | 5219 | \pnum
|
| 5220 | +The types denoted by \cv~\tcode{std::nullptr_t} are distinct types. |
5210 | 5221 | A value of type \tcode{std::nullptr_t} is a null pointer
|
5211 | 5222 | constant\iref{conv.ptr}. Such values participate in the pointer and the
|
5212 | 5223 | pointer-to-member conversions\iref{conv.ptr,conv.mem}.
|
|
5416 | 5427 | is not considered to point to an unrelated object
|
5417 | 5428 | of the object's type,
|
5418 | 5429 | even if the unrelated object is located at that address.
|
5419 |
| -A pointer value becomes invalid |
5420 |
| -when the storage it denotes |
5421 |
| -reaches the end of its storage duration; |
5422 |
| -see \ref{basic.stc}. |
5423 | 5430 | \end{note}
|
5424 | 5431 | For purposes of pointer arithmetic\iref{expr.add}
|
5425 | 5432 | and comparison\iref{expr.rel,expr.eq},
|
|
5440 | 5447 | alignment requirement.
|
5441 | 5448 | \end{note}
|
5442 | 5449 |
|
| 5450 | +\pnum |
| 5451 | +A pointer value $P$ is |
| 5452 | +\indextext{value!valid in the context of an evaluation}% |
| 5453 | +\defn{valid in the context of} an evaluation $E$ |
| 5454 | +if $P$ is a null pointer value, or |
| 5455 | +if it is a pointer to or past the end of an object $O$ and |
| 5456 | +$E$ happens before the end of the duration of the region of storage for $O$. |
| 5457 | +If a pointer value $P$ is used in an evaluation $E$ and |
| 5458 | +$P$ is not valid in the context of $E$, |
| 5459 | +then the behavior is undefined if $E$ is |
| 5460 | +an indirection\iref{expr.unary.op} or |
| 5461 | +an invocation of a deallocation function\iref{basic.stc.dynamic.deallocation}, |
| 5462 | +and \impldef{invalid pointer value in the context of an evaluation} otherwise. |
| 5463 | +\begin{footnote} |
| 5464 | +Some implementations might define that |
| 5465 | +copying such a pointer value causes a system-generated runtime fault. |
| 5466 | +\end{footnote} |
| 5467 | +\begin{note} |
| 5468 | +$P$ can be valid in the context of $E$ even |
| 5469 | +if it points to a type unrelated to that of $O$ or |
| 5470 | +if $O$ is not within its lifetime, |
| 5471 | +although further restrictions apply |
| 5472 | +to such pointer values\iref{basic.life, basic.lval, expr.add}. |
| 5473 | +\end{note} |
| 5474 | + |
5443 | 5475 | \pnum
|
5444 | 5476 | Two objects \placeholder{a} and \placeholder{b} are \defn{pointer-interconvertible} if:
|
5445 | 5477 | \begin{itemize}
|
|
6703 | 6735 | Any further (optional) parameters should be added after \tcode{argv}.
|
6704 | 6736 |
|
6705 | 6737 | \pnum
|
6706 |
| -The function \tcode{main} shall not be used within |
6707 |
| -a program. |
| 6738 | +The function \tcode{main} shall not be named by an expression. |
6708 | 6739 | \indextext{\idxcode{main} function!implementation-defined linkage of}%
|
6709 | 6740 | The linkage\iref{basic.link} of \tcode{main} is
|
6710 | 6741 | \impldef{linkage of \tcode{main}}. A program that defines \tcode{main} as
|
|
0 commit comments