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

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

Messages

Date: 2018-12-05.00:00:00

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
2018-12-05 00:00:00admincreate