Skip to content

Commit 91ea9f3

Browse files
authored
Merge 2022-07 CWG Motion 9
P2448R2 Relaxing some constexpr restrictions
2 parents b834e4e + 1557a45 commit 91ea9f3

File tree

3 files changed

+12
-141
lines changed

3 files changed

+12
-141
lines changed

source/classes.tex

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,13 +1092,6 @@
10921092
and, if the class is not abstract\iref{class.abstract}, its virtual base
10931093
classes are called its \term{potentially constructed subobjects}.
10941094

1095-
\pnum
1096-
A defaulted special member function is
1097-
\indextext{member function!constexpr-compatible}%
1098-
\defnx{constexpr-compatible}{constexpr-compatible!defaulted special member function}
1099-
if the corresponding implicitly-declared special member function
1100-
would be a constexpr function.
1101-
11021095
\rSec2[class.ctor]{Constructors}%
11031096

11041097
\rSec3[class.ctor.general]{General}%
@@ -1314,7 +1307,7 @@
13141307
If that user-written default constructor would be ill-formed,
13151308
the program is ill-formed.
13161309
If that user-written default constructor would satisfy the requirements
1317-
of a constexpr constructor\iref{dcl.constexpr}, the implicitly-defined
1310+
of a constexpr function\iref{dcl.constexpr}, the implicitly-defined
13181311
default constructor is \keyword{constexpr}.
13191312
Before the defaulted default constructor for a class is
13201313
implicitly defined,
@@ -1611,7 +1604,7 @@
16111604
its odr-use\iref{term.odr.use,class.temporary}.
16121605
\end{note}
16131606
If the implicitly-defined constructor would satisfy the requirements of a
1614-
constexpr constructor\iref{dcl.constexpr}, the implicitly-defined
1607+
constexpr function\iref{dcl.constexpr}, the implicitly-defined
16151608
constructor is \keyword{constexpr}.
16161609

16171610
\pnum
@@ -1911,20 +1904,7 @@
19111904
to assign to an object of its class type),
19121905
when it is needed for constant evaluation\iref{expr.const}, or
19131906
when it is explicitly defaulted after its first declaration.
1914-
The implicitly-defined copy/move assignment operator is \keyword{constexpr} if
1915-
\begin{itemize}
1916-
\item
1917-
\tcode{X} is a literal type, and
1918-
1919-
\item
1920-
the assignment operator selected to copy/move each direct base class subobject
1921-
is a constexpr function, and
1922-
1923-
\item
1924-
for each non-static data member of \tcode{X} that is of class type (or array
1925-
thereof), the assignment operator selected to copy/move that member is a
1926-
constexpr function.
1927-
\end{itemize}
1907+
The implicitly-defined copy/move assignment operator is \keyword{constexpr}.
19281908

19291909
\pnum
19301910
Before the defaulted copy/move assignment operator for a class is
@@ -2132,7 +2112,7 @@
21322112

21332113
\pnum
21342114
A defaulted destructor is a constexpr destructor
2135-
if it satisfies the requirements for a constexpr destructor\iref{dcl.constexpr}.
2115+
if it satisfies the requirements for a constexpr function\iref{dcl.constexpr}.
21362116

21372117
\pnum
21382118
A destructor
@@ -6503,35 +6483,6 @@
65036483
\tcode{a @ b} is a valid expression.
65046484
\end{itemize}
65056485

6506-
\pnum
6507-
A defaulted comparison function is
6508-
\indextext{operator!comparison!constexpr-compatible}%
6509-
\defnx{constexpr-compatible}{constexpr-compatible!defaulted comparison operator}
6510-
if it
6511-
satisfies the requirements for a constexpr function\iref{dcl.constexpr} and
6512-
no overload resolution
6513-
performed when determining whether to delete the function
6514-
results in a usable candidate that is a non-constexpr function.
6515-
\begin{note}
6516-
This includes the overload resolutions performed:
6517-
6518-
\begin{itemize}
6519-
\item
6520-
for an \tcode{operator<=>} whose return type is not \keyword{auto},
6521-
when determining whether a synthesized three-way comparison is defined,
6522-
6523-
\item
6524-
for an \tcode{operator<=>} whose return type is \keyword{auto} or
6525-
for an \tcode{operator==},
6526-
for a comparison between an element of the expanded list of
6527-
subobjects and itself, or
6528-
6529-
\item
6530-
for a secondary comparison operator \tcode{@},
6531-
for the expression \tcode{x @ y}.
6532-
\end{itemize}
6533-
\end{note}
6534-
65356486
\pnum
65366487
If the \grammarterm{member-specification}
65376488
does not explicitly declare

source/declarations.tex

Lines changed: 7 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -770,12 +770,6 @@
770770
The definition of a constexpr function shall satisfy the following
771771
requirements:
772772
\begin{itemize}
773-
\item
774-
its return type (if any) shall be a literal type;
775-
776-
\item
777-
each of its parameter types shall be a literal type;
778-
779773
\item
780774
it shall not be a coroutine\iref{dcl.fct.def.coroutine};
781775

@@ -816,78 +810,6 @@
816810
\end{codeblock}
817811
\end{example}
818812

819-
\pnum
820-
\indextext{specifier!\idxcode{constexpr}!constructor}%
821-
The definition of a constexpr constructor
822-
whose \grammarterm{function-body} is not \tcode{= delete}
823-
shall additionally satisfy the following requirements:
824-
\begin{itemize}
825-
826-
\item
827-
for a non-delegating constructor, every constructor selected to initialize non-static
828-
data members and base class subobjects shall be a constexpr constructor;
829-
830-
\item
831-
for a delegating constructor, the target constructor shall be a constexpr
832-
constructor.
833-
\end{itemize}
834-
835-
\begin{example}
836-
\begin{codeblock}
837-
struct Length {
838-
constexpr explicit Length(int i = 0) : val(i) { }
839-
private:
840-
int val;
841-
};
842-
\end{codeblock}
843-
\end{example}
844-
845-
\pnum
846-
The definition of a constexpr destructor
847-
whose \grammarterm{function-body} is not \tcode{= delete}
848-
shall additionally satisfy the following requirement:
849-
\begin{itemize}
850-
\item
851-
for every subobject of class type or
852-
(possibly multi-dimensional) array thereof,
853-
that class type shall have a constexpr destructor.
854-
\end{itemize}
855-
856-
\pnum
857-
For a constexpr function or constexpr constructor
858-
that is neither defaulted nor a template,
859-
if no argument values exist such that
860-
an invocation of the function or constructor could be an evaluated subexpression of a core
861-
constant expression\iref{expr.const}, or,
862-
for a constructor, an evaluated subexpression of
863-
the initialization full-expression of some constant-initialized object\iref{basic.start.static},
864-
the program is ill-formed, no diagnostic required.
865-
\begin{example}
866-
\begin{codeblock}
867-
constexpr int f(bool b)
868-
{ return b ? throw 0 : 0; } // OK
869-
constexpr int f() { return f(true); } // ill-formed, no diagnostic required
870-
871-
struct B {
872-
constexpr B(int x) : i(0) { } // \tcode{x} is unused
873-
int i;
874-
};
875-
876-
int global;
877-
878-
struct D : B {
879-
constexpr D() : B(global) { } // ill-formed, no diagnostic required
880-
// lvalue-to-rvalue conversion on non-constant \tcode{global}
881-
};
882-
883-
constexpr int f(int x) {
884-
static int n = x;
885-
return n + x; // ill-formed, no diagnostic required
886-
// all calls reach the static variable declaration
887-
}
888-
\end{codeblock}
889-
\end{example}
890-
891813
\pnum
892814
If the instantiated template specialization of a constexpr function
893815
template
@@ -896,10 +818,7 @@
896818
function,
897819
that specialization is still a constexpr function,
898820
even though a call to such a function cannot appear in a constant
899-
expression. If no specialization of the template would satisfy the
900-
requirements for a constexpr function
901-
when considered as a non-template function, the template is
902-
ill-formed, no diagnostic required.
821+
expression.
903822

904823
\pnum
905824
An invocation of a constexpr function in a given context
@@ -919,6 +838,10 @@
919838
This can indirectly cause calls to \tcode{std::is_constant_evaluated}
920839
within an invocation of the function to produce a different value.
921840
\end{note}
841+
\begin{note}
842+
It is possible to write a constexpr function for which
843+
no invocation satisfies the requirements of a core constant expression.
844+
\end{note}
922845

923846
\pnum
924847
The \keyword{constexpr} and \keyword{consteval} specifiers have no
@@ -6249,18 +6172,15 @@
62496172
\end{itemize}
62506173

62516174
\pnum
6252-
An explicitly-defaulted function that is not defined as deleted may be declared
6253-
\keyword{constexpr} or \keyword{consteval} only
6254-
if it is constexpr-compatible\iref{special,class.compare.default}.
62556175
A function explicitly defaulted on its first declaration
62566176
is implicitly inline\iref{dcl.inline},
6257-
and is implicitly constexpr\iref{dcl.constexpr} if it is constexpr-compatible.
6177+
and is implicitly constexpr\iref{dcl.constexpr}
6178+
if it satisfies the requirements for a constexpr function.
62586179

62596180
\pnum
62606181
\begin{example}
62616182
\begin{codeblock}
62626183
struct S {
6263-
constexpr S() = default; // error: implicit \tcode{S()} is not \keyword{constexpr}
62646184
S(int a = 0) = default; // error: default argument
62656185
void operator=(const S&) = default; // error: non-matching return type
62666186
~S() noexcept(false) = default; // OK, despite mismatched exception specification

source/preprocessor.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@
17601760
\defnxname{cpp_char8_t} & \tcode{201811L} \\ \rowsep
17611761
\defnxname{cpp_concepts} & \tcode{202002L} \\ \rowsep
17621762
\defnxname{cpp_conditional_explicit} & \tcode{201806L} \\ \rowsep
1763-
\defnxname{cpp_constexpr} & \tcode{202110L} \\ \rowsep
1763+
\defnxname{cpp_constexpr} & \tcode{202207L} \\ \rowsep
17641764
\defnxname{cpp_constexpr_dynamic_alloc} & \tcode{201907L} \\ \rowsep
17651765
\defnxname{cpp_constexpr_in_decltype} & \tcode{201711L} \\ \rowsep
17661766
\defnxname{cpp_consteval} & \tcode{201811L} \\ \rowsep

0 commit comments

Comments
 (0)