Language lawyer answer. All references to N3797.
7.1.5/5 states:
For a non-template, non-defaulted constexpr
function or a non-template, non-defaulted, non-inheriting constexpr
constructor, if no argument values exist such that an invocation of the function or constructor could be an evaluated subexpression of a core constant expression (5.19), the program is ill-formed; no diagnostic required.
Jumping over to 5.19, we see:
A conditional-expression e
is a core constant expression unless the evaluation of e
, following the rules of the abstract machine (1.9), would evaluate one of the following expressions:
... [lots of bullets]...
a new-expression (5.3.4);
a delete-expression (5.3.5);
... [lots more bullets]...
So no: a program containing a constexpr
function with an unconditional invocation of new
or delete
in it is ill-formed, no diagnostic required. (I'd be surprised, however, if any half-decent compiler failed to diagnose such invocations of new
or delete
in a constexpr
function, required or not.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…