Skip to content

Commit 53a0238

Browse files
authored
Merge 2024-03 CWG Motion 1
P3196R0 Core Language Working Group "ready" Issues
2 parents 9526420 + d0bd27d commit 53a0238

File tree

11 files changed

+565
-433
lines changed

11 files changed

+565
-433
lines changed

source/basic.tex

Lines changed: 78 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@
465465

466466
\pnum
467467
\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}).
470470

471471
\pnum
472472
A virtual member
@@ -537,6 +537,27 @@
537537
\end{codeblock}
538538
\end{example}
539539

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+
540561
\pnum
541562
Every program shall contain at least one definition of every
542563
function or variable that is odr-used in that program
@@ -2034,7 +2055,7 @@
20342055
its associated entities are:
20352056
the class itself;
20362057
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.
20382059
Furthermore, if \tcode{T} is a class template specialization,
20392060
its associated entities also include:
20402061
the entities
@@ -3809,38 +3830,27 @@
38093830
\item automatic storage duration
38103831
\item dynamic storage duration
38113832
\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}
38123837

38133838
\pnum
38143839
\indextext{storage duration!static}%
38153840
\indextext{storage duration!thread}%
38163841
\indextext{storage duration!automatic}%
38173842
\indextext{storage duration!dynamic}%
38183843
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
38213847
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}.
38233850

38243851
\pnum
38253852
The storage duration categories apply to references as well.
38263853

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-
38443854
\rSec3[basic.stc.static]{Static storage duration}
38453855

38463856
\pnum
@@ -3897,15 +3907,16 @@
38973907

38983908
\pnum
38993909
\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
39013911
not explicitly declared \keyword{static}, \keyword{thread_local}, or \keyword{extern} have
39023912
\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.
39063914
\begin{note}
39073915
These variables are initialized and destroyed as described in~\ref{stmt.dcl}.
39083916
\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}.
39093920

39103921
\pnum
39113922
If a variable with automatic storage duration has initialization or a destructor with side
@@ -4285,15 +4296,9 @@
42854296
Temporary objects are created
42864297
\begin{itemize}
42874298
\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
42894300
\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).
42974302
\end{itemize}
42984303
Even when the creation of the temporary object is
42994304
unevaluated\iref{expr.context},
@@ -4318,7 +4323,9 @@
43184323
when binding a reference to a prvalue\iref{dcl.init.ref,expr.type.conv,
43194324
expr.dynamic.cast,expr.static.cast,expr.const.cast,expr.cast},
43204325
\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},
43224329
\item
43234330
when performing an array-to-pointer conversion or subscripting on an array prvalue\iref{conv.array,expr.sub},
43244331
\item
@@ -4541,18 +4548,21 @@
45414548
\end{itemize}
45424549

45434550
\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
45454552
is created in the \grammarterm{for-range-initializer} of a range-based \keyword{for} statement.
45464553
If such a temporary object would otherwise be destroyed
45474554
at the end of the \grammarterm{for-range-initializer} full-expression,
45484555
the object persists for the lifetime of the reference
45494556
initialized by the \grammarterm{for-range-initializer}.
45504557

45514558
\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}.
45564566
If the lifetime of two or more temporaries
45574567
with lifetimes extending beyond the full-expressions in which they were created
45584568
ends at the same point,
@@ -5207,6 +5217,7 @@
52075217
to type \cv{}~\keyword{void}.
52085218

52095219
\pnum
5220+
The types denoted by \cv~\tcode{std::nullptr_t} are distinct types.
52105221
A value of type \tcode{std::nullptr_t} is a null pointer
52115222
constant\iref{conv.ptr}. Such values participate in the pointer and the
52125223
pointer-to-member conversions\iref{conv.ptr,conv.mem}.
@@ -5416,10 +5427,6 @@
54165427
is not considered to point to an unrelated object
54175428
of the object's type,
54185429
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}.
54235430
\end{note}
54245431
For purposes of pointer arithmetic\iref{expr.add}
54255432
and comparison\iref{expr.rel,expr.eq},
@@ -5440,6 +5447,31 @@
54405447
alignment requirement.
54415448
\end{note}
54425449

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+
54435475
\pnum
54445476
Two objects \placeholder{a} and \placeholder{b} are \defn{pointer-interconvertible} if:
54455477
\begin{itemize}
@@ -6703,8 +6735,7 @@
67036735
Any further (optional) parameters should be added after \tcode{argv}.
67046736

67056737
\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.
67086739
\indextext{\idxcode{main} function!implementation-defined linkage of}%
67096740
The linkage\iref{basic.link} of \tcode{main} is
67106741
\impldef{linkage of \tcode{main}}. A program that defines \tcode{main} as

0 commit comments

Comments
 (0)