|
212 | 212 | \nontermdef{selection-statement}\br
|
213 | 213 | \keyword{if} \opt{\keyword{constexpr}} \terminal{(} \opt{init-statement} condition \terminal{)} statement\br
|
214 | 214 | \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 |
215 | 217 | \keyword{switch} \terminal{(} \opt{init-statement} condition \terminal{)} statement
|
216 | 218 | \end{bnf}
|
217 | 219 |
|
|
315 | 317 | except that the \grammarterm{init-statement} is
|
316 | 318 | in the same scope as the \grammarterm{condition}.
|
317 | 319 |
|
| 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 | + |
318 | 371 | \rSec2[stmt.switch]{The \tcode{switch} statement}%
|
319 | 372 | \indextext{statement!\idxcode{switch}}
|
320 | 373 |
|
|
0 commit comments