|
954 | 954 | declaration, |
955 | 955 | \grammarterm{parameter-declaration-clause}, |
956 | 956 | \grammarterm{statement}, |
957 | | -\grammarterm{handler}, or |
| 957 | +\grammarterm{handler}, |
| 958 | +\grammarterm{lambda-expression}, or |
958 | 959 | contract assertion |
959 | 960 | (as described in the following subclauses of \ref{basic.scope}) |
960 | 961 | appearing in another scope, which thereby contains $S$. |
|
2887 | 2888 | \indextext{program}% |
2888 | 2889 | \indextext{linking}% |
2889 | 2890 | A \defn{program} consists of one or more translation units\iref{lex.phases} |
2890 | | -linked together. A translation unit consists |
2891 | | -of a sequence of declarations. |
| 2891 | +that are translated and linked together. |
| 2892 | +A translation unit consists of a sequence of declarations. |
2892 | 2893 |
|
2893 | 2894 | \begin{bnf} |
2894 | 2895 | \nontermdef{translation-unit}\br |
|
3476 | 3477 | An object that is not a subobject of any other object is called a \defn{complete |
3477 | 3478 | object}. |
3478 | 3479 | If an object is created |
3479 | | -in storage associated with a member subobject or array element \placeholder{e} |
| 3480 | +in storage associated with a subobject \placeholder{e} |
3480 | 3481 | (which may or may not be within its lifetime), |
3481 | 3482 | the created object |
3482 | 3483 | is a subobject of \placeholder{e}'s containing object if |
|
3486 | 3487 | \item |
3487 | 3488 | the storage for the new object exactly overlays the storage location associated with \placeholder{e}, and |
3488 | 3489 | \item |
| 3490 | +\placeholder{e} is not a potentially-overlapping subobject, and |
| 3491 | +\item |
3489 | 3492 | the new object is of the same type as \placeholder{e} (ignoring cv-qualification). |
3490 | 3493 | \end{itemize} |
| 3494 | +In this case, \placeholder{e} and the created object are |
| 3495 | +\defnadjx{corresponding direct}{subobjects}{subobject}. |
3491 | 3496 |
|
3492 | 3497 | \pnum |
3493 | 3498 | \indextext{object!providing storage for}% |
|
3940 | 3945 | the pointer is used to access a non-static data member or call a |
3941 | 3946 | non-static member function of the object, or |
3942 | 3947 | \item |
3943 | | - the pointer is implicitly converted\iref{conv.ptr} to a pointer |
3944 | | - to a virtual base class, or |
3945 | | -\item |
3946 | | - the pointer is used as the operand of a |
3947 | | - \keyword{static_cast}\iref{expr.static.cast}, except when the conversion |
3948 | | - is to pointer to \cv{}~\keyword{void}, or to pointer to \cv{}~\keyword{void} |
3949 | | - and subsequently to pointer to |
3950 | | - \cv{}~\keyword{char}, |
3951 | | - \cv{}~\tcode{\keyword{unsigned} \keyword{char}}, or |
3952 | | - \cv{}~\tcode{std::byte}\iref{cstddef.syn}, or |
| 3948 | + the pointer is converted\iref{conv.ptr,expr.static.cast} to a pointer |
| 3949 | + to a virtual base class or to a base class thereof, or |
3953 | 3950 | \item |
3954 | 3951 | the pointer is used as the operand of a |
3955 | 3952 | \keyword{dynamic_cast}\iref{expr.dynamic.cast}. |
|
4012 | 4009 | \end{note} |
4013 | 4010 |
|
4014 | 4011 | \pnum |
4015 | | -An object $o_1$ is \defn{transparently replaceable} by an object $o_2$ if |
| 4012 | +An object $o_1$ is \defn{transparently replaceable} by an object $o_2$ if either |
| 4013 | +\begin{itemize} |
| 4014 | +\item |
| 4015 | +$o_1$ and $o_2$ are complete objects for which: |
4016 | 4016 | \begin{itemize} |
| 4017 | +\item $o_1$ is not const, |
4017 | 4018 | \item the storage that $o_2$ occupies exactly overlays |
4018 | 4019 | the storage that $o_1$ occupied, and |
4019 | | - |
4020 | 4020 | \item $o_1$ and $o_2$ are of the same type |
4021 | | -(ignoring the top-level cv-qualifiers), and |
4022 | | - |
4023 | | -\item $o_1$ is not a const, complete object, and |
4024 | | - |
4025 | | -\item neither $o_1$ nor $o_2$ |
4026 | | -is a potentially-overlapping subobject\iref{intro.object}, and |
| 4021 | +(ignoring the top-level cv-qualifiers), or |
| 4022 | +\end{itemize} |
4027 | 4023 |
|
4028 | | -\item either $o_1$ and $o_2$ are both complete objects, or |
4029 | | -$o_1$ and $o_2$ are direct subobjects of objects $p_1$ and $p_2$, respectively, |
4030 | | -and $p_1$ is transparently replaceable by $p_2$. |
| 4024 | +\item |
| 4025 | +$o_1$ and $o_2$ are corresponding direct subobjects\iref{intro.object} for which: |
| 4026 | +\begin{itemize} |
| 4027 | +\item the complete object of $o_1$ is not const or |
| 4028 | +\item $o_1$ is a mutable member subobject or a subobject thereof. |
| 4029 | +\end{itemize} |
4031 | 4030 | \end{itemize} |
4032 | 4031 |
|
4033 | 4032 | \pnum |
|
4812 | 4811 | \item |
4813 | 4812 | a class member access\iref{expr.ref} using the \tcode{.} operator |
4814 | 4813 | where the left operand is one of these expressions and |
4815 | | - the right operand designates a non-static data member of non-reference type, |
| 4814 | + the right operand designates |
| 4815 | + a non-static data member\iref{class.mem.general} of non-reference type or |
| 4816 | + a direct base class relationship\iref{class.derived.general}, |
4816 | 4817 | \item |
4817 | 4818 | a pointer-to-member operation\iref{expr.mptr.oper} using the \tcode{.*} operator |
4818 | 4819 | where the left operand is one of these expressions and |
|
4830 | 4831 | to a glvalue that refers |
4831 | 4832 | to the object designated by the operand, or |
4832 | 4833 | to its complete object or a subobject thereof, |
| 4834 | +\item |
| 4835 | + an explicit type conversion (functional notation)\iref{expr.type.conv} |
| 4836 | + to a reference type whose initializer is a \grammarterm{braced-init-list} |
| 4837 | + where the reference is |
| 4838 | + \begin{itemize} |
| 4839 | + \item bound directly to the glvalue result of one of these expressions |
| 4840 | + (necessarily the sole element of the \grammarterm{braced-init-list}) or |
| 4841 | + \item bound to the result of a temporary materialization conversion, |
| 4842 | + \end{itemize} |
4833 | 4843 | \item |
4834 | 4844 | a conditional expression\iref{expr.cond} that is a glvalue |
4835 | 4845 | where the second or third operand is one of these expressions, or |
|
5592 | 5602 | is an incomplete type that cannot be completed; such a type has |
5593 | 5603 | an empty set of values. It is used as the return |
5594 | 5604 | type for functions that do not return a value. |
5595 | | -An expression of type \cv{}~\keyword{void} shall |
5596 | | -be used only as |
| 5605 | +\begin{note} |
| 5606 | +An expression of type \cv{}~\keyword{void} can be used as |
5597 | 5607 | \begin{itemize} |
5598 | 5608 | \item an expression statement\iref{stmt.expr}, |
5599 | 5609 | \item the expression in a \keyword{return} statement\iref{stmt.return} |
5600 | 5610 | for a function with the return type \cv{}~\keyword{void}, |
5601 | 5611 | \item an operand of a comma expression\iref{expr.comma}, |
| 5612 | +\item the operand of a parenthesized expression\iref{expr.prim.paren}, |
| 5613 | +\item a requirement in a \grammarterm{requires-expression}\iref{expr.prim.req.general}, |
5602 | 5614 | \item the second or third operand of \tcode{?:}\iref{expr.cond}, |
5603 | 5615 | \item the operand of a \keyword{typeid} expression\iref{expr.typeid}, |
5604 | 5616 | \item the operand of a \keyword{noexcept} operator\iref{expr.unary.noexcept}, |
5605 | 5617 | \item the operand of a \keyword{decltype} specifier\iref{dcl.type.decltype}, or |
5606 | 5618 | \item the operand of an explicit conversion to type |
5607 | 5619 | \cv{}~\keyword{void}\iref{expr.type.conv,expr.static.cast,expr.cast}. |
5608 | 5620 | \end{itemize} |
| 5621 | +\end{note} |
5609 | 5622 |
|
5610 | 5623 | \pnum |
5611 | 5624 | The types denoted by \cv~\tcode{std::nullptr_t} are distinct types. |
|
7170 | 7183 | \indextext{\idxcode{main} function!implementation-defined parameters to}% |
7171 | 7184 | An implementation shall allow both |
7172 | 7185 | \begin{itemize} |
7173 | | -\item a function of \tcode{()} returning \keyword{int} and |
7174 | | -\item a function of \tcode{(\keyword{int}}, pointer to pointer to \tcode{\keyword{char})} returning \keyword{int} |
| 7186 | +\item |
| 7187 | +an ``optionally \tcode{noexcept} function of |
| 7188 | +\tcode{()} returning \keyword{int}'' and |
| 7189 | +\item |
| 7190 | +an ``optionally \tcode{noexcept} function of |
| 7191 | +\tcode{(\keyword{int}}, pointer to pointer to \tcode{\keyword{char})} |
| 7192 | +returning \keyword{int}'' |
7175 | 7193 | \end{itemize} |
7176 | 7194 | \indextext{\idxcode{argc}}% |
7177 | 7195 | \indextext{\idxcode{argv}}% |
|
7489 | 7507 | \indextext{program!termination|(}% |
7490 | 7508 | \indextext{object!destructor static}% |
7491 | 7509 | \indextext{\idxcode{main} function!return from}% |
7492 | | -Constructed objects\iref{dcl.init} |
| 7510 | +Constructed complete objects\iref{dcl.init} |
7493 | 7511 | with static storage duration are destroyed |
7494 | 7512 | and functions registered with \tcode{std::atexit} |
7495 | 7513 | are called as part of a call to |
|
7503 | 7521 | \end{note} |
7504 | 7522 |
|
7505 | 7523 | \pnum |
7506 | | -Constructed objects with thread storage duration within a given thread |
| 7524 | +Constructed complete objects with thread storage duration within a given thread |
7507 | 7525 | are destroyed as a result of returning from the initial function of that thread and as a |
7508 | 7526 | result of that thread calling \tcode{std::exit}. |
7509 | | -The destruction of all constructed objects with thread storage |
7510 | | -duration within that thread strongly happens before destroying |
| 7527 | +The destruction of those constructed objects |
| 7528 | +is sequenced before releasing the storage for |
| 7529 | +any object with thread storage duration within that thread\iref{basic.stc.thread}. |
| 7530 | +The destruction of those constructed objects |
| 7531 | +strongly happens before destroying |
7511 | 7532 | any object with static storage duration. |
7512 | 7533 |
|
7513 | 7534 | \pnum |
7514 | | -If the completion of the constructor or dynamic initialization of an object with static |
7515 | | -storage duration strongly happens before that of another, the completion of the destructor |
7516 | | -of the second is sequenced before the initiation of the destructor of the first. |
7517 | | -If the completion of the constructor or dynamic initialization of an object with thread |
7518 | | -storage duration is sequenced before that of another, the completion of the destructor |
7519 | | -of the second is sequenced before the initiation of the destructor of the first. |
| 7535 | +The destruction of a complete object with thread storage duration within a given thread |
| 7536 | +and having constant destruction\iref{expr.const} |
| 7537 | +is sequenced after the destruction of any other complete object |
| 7538 | +with thread storage duration within the thread. |
| 7539 | +The destruction of a complete object with static storage duration |
| 7540 | +and having constant destruction |
| 7541 | +is sequenced after the destruction of any other complete object |
| 7542 | +with static storage duration |
| 7543 | +and after any call to a function passed to \tcode{std::atexit}. |
| 7544 | +The sequencing rules in the remainder of this subclause |
| 7545 | +apply only to complete objects not having constant destruction. |
| 7546 | + |
| 7547 | +\pnum |
| 7548 | +If the deemed construction\iref{dcl.init.general} of a complete object with static |
| 7549 | +storage duration strongly happens before that of another, the completion of the destruction |
| 7550 | +of the second is sequenced before the initiation of the destruction of the first. |
| 7551 | +If the deemed construction of a complete object with thread |
| 7552 | +storage duration is sequenced before that of another, the completion of the destruction |
| 7553 | +of the second is sequenced before the initiation of the destruction of the first. |
7520 | 7554 | If an object is |
7521 | 7555 | initialized statically, the object is destroyed in the same order as if |
7522 | | -the object was dynamically initialized. For an object of array or class |
7523 | | -type, all subobjects of that object are destroyed before any block |
7524 | | -variable with static storage duration initialized during the construction |
7525 | | -of the subobjects is destroyed. |
| 7556 | +the object was dynamically initialized. |
7526 | 7557 | If the destruction of an object with static or thread storage duration |
7527 | 7558 | exits via an exception, |
7528 | 7559 | the function \tcode{std::terminate} is called\iref{except.terminate}. |
| 7560 | +\begin{example} |
| 7561 | +In the following program, |
| 7562 | +the elements of \tcode{a} are destroyed, |
| 7563 | +followed by \tcode{dt}, and |
| 7564 | +finally by the two \tcode{Btemp} objects: |
| 7565 | +\begin{codeblock} |
| 7566 | +struct DTemp { ~DTemp(); }; |
| 7567 | +struct Temp { |
| 7568 | + ~Temp() { |
| 7569 | + static DTemp dt; |
| 7570 | + } |
| 7571 | +}; |
| 7572 | +struct BTemp { |
| 7573 | + ~BTemp(); |
| 7574 | +}; |
| 7575 | +struct A { |
| 7576 | + const BTemp &tb; |
| 7577 | + ~A(); |
| 7578 | +}; |
| 7579 | +A a[] = { (Temp(), BTemp()), BTemp() }; |
| 7580 | + |
| 7581 | +int main() {} |
| 7582 | +\end{codeblock} |
| 7583 | +If the array \tcode{a} were an object with automatic storage duration, |
| 7584 | +the \tcode{Btemp} temporaries would be destroyed |
| 7585 | +as each element of the array is destroyed\iref{class.temporary}. |
| 7586 | +\end{example} |
7529 | 7587 |
|
7530 | 7588 | \pnum |
7531 | 7589 | If a function contains a block variable of static or thread storage duration that has been |
|
7541 | 7599 | \pnum |
7542 | 7600 | \indextext{\idxcode{atexit}}% |
7543 | 7601 | \indexlibraryglobal{atexit}% |
7544 | | -If the completion of the initialization of an object with static storage |
| 7602 | +If the deemed construction of a complete object with static storage |
7545 | 7603 | duration strongly happens before a call to \tcode{std::atexit}~(see |
7546 | 7604 | \libheader{cstdlib}, \ref{support.start.term}), the call to the function passed to |
7547 | | -\tcode{std::atexit} is sequenced before the call to the destructor for the object. If a |
7548 | | -call to \tcode{std::atexit} strongly happens before the completion of the initialization of |
7549 | | -an object with static storage duration, the call to the destructor for the |
| 7605 | +\tcode{std::atexit} is sequenced before the initiation of the destruction of the object. |
| 7606 | +If a call to \tcode{std::atexit} strongly happens before the deemed construction of |
| 7607 | +a complete object with static storage duration, |
| 7608 | +the completion of the destruction of the |
7550 | 7609 | object is sequenced before the call to the function passed to \tcode{std::atexit}. If a |
7551 | 7610 | call to \tcode{std::atexit} strongly happens before another call to \tcode{std::atexit}, the |
7552 | 7611 | call to the function passed to the second \tcode{std::atexit} call is sequenced before |
|
0 commit comments