Skip to content

Commit 35f6932

Browse files
committed
Merge 2021-06 CWG Motion 2
P1938R3 if consteval
2 parents bcfef14 + bf942fa commit 35f6932

File tree

4 files changed

+71
-6
lines changed

4 files changed

+71
-6
lines changed

source/expressions.tex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7476,9 +7476,15 @@
74767476

74777477
\pnum
74787478
An expression or conversion is in an \defn{immediate function context}
7479-
if it is potentially evaluated and
7479+
if it is potentially evaluated and either:
7480+
\begin{itemize}
7481+
\item
74807482
its innermost enclosing non-block scope is
7481-
a function parameter scope of an immediate function.
7483+
a function parameter scope of an immediate function, or
7484+
\item
7485+
its enclosing statement is enclosed\iref{stmt.pre} by
7486+
the \grammarterm{compound-statement} of a consteval if statement\iref{stmt.if}.
7487+
\end{itemize}
74827488
An expression or conversion is an \defn{immediate invocation}
74837489
if it is a potentially-evaluated explicit or implicit invocation of
74847490
an immediate function and

source/preprocessor.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,7 @@
17801780
\defnxname{cpp_generic_lambdas} & \tcode{201707L} \\ \rowsep
17811781
\defnxname{cpp_guaranteed_copy_elision} & \tcode{201606L} \\ \rowsep
17821782
\defnxname{cpp_hex_float} & \tcode{201603L} \\ \rowsep
1783+
\defnxname{cpp_if_consteval} & \tcode{202106L} \\ \rowsep
17831784
\defnxname{cpp_if_constexpr} & \tcode{201606L} \\ \rowsep
17841785
\defnxname{cpp_impl_coroutine} & \tcode{201902L} \\ \rowsep
17851786
\defnxname{cpp_impl_destroying_delete} & \tcode{201806L} \\ \rowsep

source/statements.tex

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@
212212
\nontermdef{selection-statement}\br
213213
\keyword{if} \opt{\keyword{constexpr}} \terminal{(} \opt{init-statement} condition \terminal{)} statement\br
214214
\keyword{if} \opt{\keyword{constexpr}} \terminal{(} \opt{init-statement} condition \terminal{)} statement \keyword{else} statement\br
215+
\keyword{if} \opt{\terminal{!}} \keyword{consteval} compound-statement\br
216+
\keyword{if} \opt{\terminal{!}} \keyword{consteval} compound-statement \keyword{else} statement\br
215217
\keyword{switch} \terminal{(} \opt{init-statement} condition \terminal{)} statement
216218
\end{bnf}
217219

@@ -315,6 +317,57 @@
315317
except that the \grammarterm{init-statement} is
316318
in the same scope as the \grammarterm{condition}.
317319

320+
\pnum
321+
An \keyword{if} statement of the form \tcode{\keyword{if} \keyword{consteval}}
322+
is called a \defnadj{consteval if}{statement}.
323+
The \grammarterm{statement}, if any, in a consteval if statement
324+
shall be a \grammarterm{compound-statement}.
325+
\begin{example}
326+
\begin{codeblock}
327+
constexpr void f(bool b) {
328+
if (true)
329+
if consteval { }
330+
else ; // error: not a \grammarterm{compound-statement}; \keyword{else} not associated with outer \keyword{if}
331+
}
332+
\end{codeblock}
333+
\end{example}
334+
335+
\pnum
336+
If a consteval if statement is evaluated in a context
337+
that is manifestly constant-evaluated\iref{expr.const},
338+
the first substatement is executed.
339+
\begin{note}
340+
The first substatement is an immediate function context.
341+
\end{note}
342+
Otherwise, if the \keyword{else} part of the selection statement is present,
343+
then the second substatement is executed.
344+
A \keyword{case} or \keyword{default} label
345+
appearing within such an \keyword{if} statement
346+
shall be associated with a \keyword{switch} statement
347+
within the same \keyword{if} statement.
348+
A label declared in a substatement of a consteval if statement
349+
shall only be referred to by a statement in the same substatement.
350+
351+
\pnum
352+
An \keyword{if} statement of the form
353+
\begin{ncsimplebnf}
354+
\keyword{if} \terminal{!} \keyword{consteval} compound-statement
355+
\end{ncsimplebnf}
356+
is not itself a consteval if statement,
357+
but is equivalent to the consteval if statement
358+
\begin{ncsimplebnf}
359+
\keyword{if} \keyword{consteval} \terminal{\{} \terminal{\}} \keyword{else} compound-statement
360+
\end{ncsimplebnf}
361+
An \keyword{if} statement of the form
362+
\begin{ncsimplebnf}
363+
\keyword{if} \terminal{!} \keyword{consteval} compound-statement$_1$ \keyword{else} statement$_2$
364+
\end{ncsimplebnf}
365+
is not itself a consteval if statement,
366+
but is equivalent to the consteval if statement
367+
\begin{ncsimplebnf}
368+
\keyword{if} \keyword{consteval} statement$_2$ \keyword{else} compound-statement$_1$
369+
\end{ncsimplebnf}
370+
318371
\rSec2[stmt.switch]{The \tcode{switch} statement}%
319372
\indextext{statement!\idxcode{switch}}
320373

source/utilities.tex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18143,10 +18143,15 @@
1814318143

1814418144
\begin{itemdescr}
1814518145
\pnum
18146-
\returns
18147-
\tcode{true} if and only if evaluation of the call occurs
18148-
within the evaluation of an expression or conversion
18149-
that is manifestly constant-evaluated\iref{expr.const}.
18146+
\effects
18147+
Equivalent to:
18148+
\begin{codeblock}
18149+
if consteval {
18150+
return true;
18151+
} else {
18152+
return false;
18153+
}
18154+
\end{codeblock}
1815018155

1815118156
\pnum
1815218157
\begin{example}

0 commit comments

Comments
 (0)