Title
Loops in constant expressions
Status
drwp
Section
7.7 [expr.const]
Submitter
Daniel Krügler

Created on 2023-03-23.00:00:00 last changed 12 months ago

Messages

Date: 2023-04-28.19:41:23

Proposed resolution (approved by CWG 2023-04-28):

Change in 7.7 [expr.const] bullet 5.30 as follows:

An expression E is a core constant expression unless the evaluation of E, following the rules of the abstract machine (6.9.1 [intro.execution]), would evaluate one of the following:
  • ...
  • a goto statement (8.7.6 [stmt.goto]). [ Note: A goto statement introduced by equivalence (Clause 8 [stmt.stmt]) is not in scope. For example, a while statement (8.6.2 [stmt.while]) can be executed during constant evaluation. -- end note ].
Date: 2023-03-31.21:39:35

CWG 2023-03-30

Keep the rule non-normative and non-exhaustive.

Date: 2023-06-13.16:05:19

Suggested resolution [SUPERSEDED]:

Change in 7.7 [expr.const] bullet 5.30 as follows:

An expression E is a core constant expression unless the evaluation of E, following the rules of the abstract machine (6.9.1 [intro.execution]), would evaluate one of the following:
  • ...
  • a goto statement (8.7.6 [stmt.goto]) unless it is introduced by replacing an iteration-statement (8.6 [stmt.iter]) or a continue statement (8.7.3 [stmt.cont]) with its equivalent.
Date: 2023-06-15.00:00:00

[Accepted as a DR at the June, 2023 meeting.]

Iteration statements such as while and for loops are specified by equivalent code involving goto (8.6.2 [stmt.while] paragraph 2, 8.6.4 [stmt.for] paragraph 1, 8.6.5 [stmt.ranged] paragraph 1). The goto statement cannot be evaluated in constant expressions (7.7 [expr.const] bullet 5.30), thus while and for loops cannot be evaluated in constant expressions. Similar concerns arise for continue (8.7.3 [stmt.cont] paragraph 1).

However, that is neither intended nor existing practice.

History
Date User Action Args
2023-12-19 10:15:28adminsetstatus: dr -> drwp
2023-07-16 13:00:43adminsetstatus: ready -> dr
2023-04-28 19:41:23adminsetstatus: review -> ready
2023-03-31 21:39:35adminsetmessages: + msg7240
2023-03-31 21:39:35adminsetmessages: + msg7239
2023-03-31 21:39:35adminsetstatus: open -> review
2023-03-23 17:48:23adminsetmessages: + msg7235
2023-03-23 00:00:00admincreate