Created on 2022-09-07.00:00:00 last changed 17 months ago
Proposed resolution (approved by CWG 2022-11-09):
Change in 8.1 [stmt.pre] paragraph 5 as follows:
...The value of a condition that is an initialized declaration in a switch statement is the value of the declared variable if it has integral or enumeration type, or of that variable implicitly converted to integral or enumeration type otherwise....
Change in 8.5.3 [stmt.switch] paragraph 2 as follows:
The value of a condition that is an initialized declaration is the value of the declared variable, or the value of the expression otherwise. The value of the condition shall be of integral type, enumeration type, or class type. If of class type, the condition is contextually implicitly converted (7.3 [conv]) to an integral or enumeration type. If the (possibly converted) type is subject to integral promotions (7.3.7 [conv.prom]), the condition is converted to the promoted type. ...
CWG telecon 2022-10-21:
Rewording is needed.
[Accepted as a DR at the November, 2022 meeting.]
Consider:
switch(float v = 0) { case 0: ; }
Subclause 8.1 [stmt.pre] paragraph 5 specifies:
... The value of a condition that is an initialized declaration in a switch statement is the value of the declared variable if it has integral or enumeration type, or of that variable implicitly converted to integral or enumeration type otherwise. ...
That appears to permit variables of floating-point type, whose value can be converted to integral type. In contrast, expressions of floating-point type are prohibited by 8.5.3 [stmt.switch] paragraph 2:
The condition shall be of integral type, enumeration type, or class type. ...
Possible resolution [SUPERSEDED]:
Change in 8.1 [stmt.pre] paragraph 5 as follows:
... The value of a condition that is an initialized declaration in a switch statement is the value of the declared variable if it has integral or enumeration type, or of that variable implicitly converted to integral or enumeration type if it has class type; otherwise the program is ill-formed. ...
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-07-16 13:00:43 | admin | set | status: open -> c++23 |
2023-07-16 13:00:43 | admin | set | status: drwp -> open |
2023-02-18 18:43:04 | admin | set | status: dr -> drwp |
2022-11-25 05:14:04 | admin | set | status: ready -> dr |
2022-11-10 14:48:13 | admin | set | status: review -> ready |
2022-11-10 14:48:13 | admin | set | messages: + msg7014 |
2022-11-10 14:48:13 | admin | set | status: review -> review |
2022-11-10 14:48:13 | admin | set | status: review -> review |
2022-11-10 14:48:13 | admin | set | messages: + msg6994 |
2022-11-10 14:48:13 | admin | set | status: review -> review |
2022-10-30 07:00:36 | admin | set | status: open -> review |
2022-10-30 07:00:36 | admin | set | status: open -> open |
2022-10-30 07:00:36 | admin | set | status: open -> open |
2022-10-30 07:00:36 | admin | set | status: open -> open |
2022-10-30 06:54:54 | admin | set | status: ready -> open |
2022-10-30 06:54:54 | admin | set | status: ready -> ready |
2022-10-30 06:54:54 | admin | set | status: ready -> ready |
2022-09-07 00:00:00 | admin | create |