Title
new-expression size check and constant evaluation
Status
c++23
Section
7.7 [expr.const]
Submitter
Tam S. B

Created on 2018-12-05.00:00:00 last changed 16 months ago

Messages

Date: 2022-11-20.07:54:16

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...
Date: 2022-11-20.07:54:16

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.

Date: 2022-11-15.00:00:00

[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:43adminsetstatus: open -> c++23
2023-07-16 13:00:43adminsetstatus: drwp -> open
2023-02-18 18:43:04adminsetstatus: dr -> drwp
2022-11-25 05:14:04adminsetstatus: ready -> dr
2022-11-20 07:54:16adminsetmessages: + msg7039
2022-09-24 20:24:20adminsetmessages: + msg6945
2022-09-24 20:24:20adminsetstatus: drafting -> ready
2022-09-09 20:27:40adminsetstatus: open -> drafting
2018-12-05 00:00:00admincreate