Skip to content

Commit 011e687

Browse files
burblebeetkoeppe
authored andcommitted
CWG2924 Undefined behavior during constant evaluation
1 parent 1811723 commit 011e687

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

source/declarations.tex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9015,6 +9015,7 @@
90159015

90169016
\rSec2[dcl.attr.assume]{Assumption attribute}
90179017

9018+
% FIXME: Shouldn't there be a pnum here?
90189019
The \grammarterm{attribute-token} \tcode{assume} may be applied to a null statement;
90199020
such a statement is an \defn{assumption}.
90209021
An \grammarterm{attribute-argument-clause} shall be present and
@@ -9027,7 +9028,8 @@
90279028
If the converted expression would evaluate to \tcode{true}
90289029
at the point where the assumption appears,
90299030
the assumption has no effect.
9030-
Otherwise, the behavior is undefined.
9031+
Otherwise,
9032+
evaluation of the assumption has runtime-undefined behavior.
90319033
\begin{note}
90329034
The expression is potentially evaluated\iref{basic.def.odr}.
90339035
The use of assumptions is intended to allow implementations
@@ -9534,8 +9536,9 @@
95349536
translation unit, the program is ill-formed, no diagnostic required.
95359537

95369538
\pnum
9537-
If a function \tcode{f} is called where \tcode{f} was previously declared with the \tcode{noreturn}
9538-
attribute and \tcode{f} eventually returns, the behavior is undefined.
9539+
If a function \tcode{f} is invoked where \tcode{f} was previously declared with the \tcode{noreturn}
9540+
attribute and that invocation eventually returns,
9541+
the behavior is runtime-undefined.
95399542
\begin{note}
95409543
The function can
95419544
terminate by throwing an exception.

source/expressions.tex

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7596,8 +7596,7 @@
75967596

75977597
\item
75987598
an operation that would have undefined or erroneous behavior
7599-
as specified in \ref{intro} through \ref{\lastcorechapter},
7600-
excluding \ref{dcl.attr.assume} and \ref{dcl.attr.noreturn};
7599+
as specified in \ref{intro} through \ref{\lastcorechapter};
76017600
\begin{footnote}
76027601
This includes,
76037602
for example, signed integer overflow\iref{expr.pre}, certain
@@ -7778,33 +7777,23 @@
77787777
\end{note}
77797778
\end{itemize}
77807779

7780+
\pnum
7781+
It is
7782+
\impldef{whether an expression is a core constant expression}
7783+
whether $E$ is a core constant expression
7784+
if $E$ satisfies the constraints of a core constant expression, but
7785+
evaluation of $E$ has runtime-undefined behavior.
7786+
77817787
\pnum
77827788
It is unspecified whether $E$ is a core constant expression
77837789
if $E$ satisfies the constraints of a core constant expression, but
77847790
evaluation of $E$ would evaluate
77857791
\begin{itemize}
77867792
\item
77877793
an operation that has undefined behavior
7788-
as specified in \ref{library} through \ref{\lastlibchapter},
7794+
as specified in \ref{library} through \ref{\lastlibchapter} or
77897795
\item
7790-
an invocation of the \tcode{va_start} macro\iref{cstdarg.syn},
7791-
\item
7792-
a call to a function
7793-
that was previously declared
7794-
with the \tcode{noreturn} attribute\iref{dcl.attr.noreturn} and
7795-
that call returns to its caller, or
7796-
\item
7797-
a statement with an assumption\iref{dcl.attr.assume}
7798-
whose converted \grammarterm{conditional-expression},
7799-
if evaluated where the assumption appears,
7800-
would not disqualify $E$ from being a core constant expression and
7801-
would not evaluate to \tcode{true}.
7802-
\begin{note}
7803-
$E$ is not disqualified from being a core constant expression
7804-
if the hypothetical evaluation of
7805-
the converted \grammarterm{conditional-expression}
7806-
would disqualify $E$ from being a core constant expression.
7807-
\end{note}
7796+
an invocation of the \tcode{va_start} macro\iref{cstdarg.syn}.
78087797
\end{itemize}
78097798

78107799
\pnum

source/intro.tex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@
206206
constructs that it does not support.
207207
\end{defnote}
208208

209+
\definition{constant evaluation}{defns.const.eval}
210+
\indexdefn{constant evaluation}%
211+
evaluation that is performed as part of evaluating an expression
212+
as a core constant expression\iref{expr.const}
213+
209214
\definition{constant subexpression}{defns.const.subexpr}
210215
\indexdefn{constant subexpression}%
211216
expression whose evaluation as subexpression of a
@@ -504,6 +509,23 @@
504509
\indextext{undefined}
505510
\end{defnote}
506511

512+
\definition{runtime-undefined behavior}{defns.undefined.runtime}
513+
\indexdefn{behavior!runtime-undefined}%
514+
behavior that is undefined except when it occurs during constant evaluation
515+
516+
\begin{defnote}
517+
During constant evaluation,
518+
\begin{itemize}
519+
\item
520+
it is
521+
\impldef{whether runtime-undefined behavior results in the expression being deemed non-constant}
522+
whether runtime-undefined behavior results in the expression being deemed non-constant
523+
(as specified in~\ref{expr.const}) and
524+
\item
525+
runtime-undefined behavior has no other effect.
526+
\end{itemize}
527+
\end{defnote}
528+
507529
\indexdefn{signature}%
508530
\definition{signature}{defns.signature}
509531
\defncontext{function}

0 commit comments

Comments
 (0)