Created on 2018-12-05.00:00:00 last changed 16 months ago
Proposed resolution (approved by CWG 2022-09-23):
Change in 7.6.2.8 [expr.new] paragraph 8 as follows:
If the expression is erroneous after converting to std::size_t:
- if the expression is a potentially-evaluated core constant expression, the program is ill-formed;
- otherwise, an allocation function is not called; instead...
CWG telecon 2022-09-09:
The example should be well-formed, because f is not instantiated.
A similar situation arises for narrowing conversions, except that in the latter case, determining the value at compile-time empowers to allow additional cases, whereas the new-expression case uses a compile-time value to prohibit additional cases.
[Accepted as a DR at the November, 2022 meeting.]
According to 7.6.2.8 [expr.new] paragraph 8, if the expression in a noptr-new-declarator is a core constant expression, the program is ill-formed if the expression is erroneous, e.g., negative. However, consider the following example:
template<class T = void> constexpr int f() { T t; return 1; } using _ = decltype(new int[f()]);
f() is a core constant expression, so it must be evaluated to determine its value. However, because the expression appears in an unevaluated operand, it is not “potentially constant evaluated” and thus f is not “needed for constant evaluation”, so the template is not instantiated (13.9.2 [temp.inst] paragraph 7). There is implementation divergence on the handling of this example.
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-20 07:54:16 | admin | set | messages: + msg7039 |
2022-09-24 20:24:20 | admin | set | messages: + msg6945 |
2022-09-24 20:24:20 | admin | set | status: drafting -> ready |
2022-09-09 20:27:40 | admin | set | status: open -> drafting |
2018-12-05 00:00:00 | admin | create |