https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95785

Tyler Smith <whitesmith137 at outlook dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |whitesmith137 at outlook dot 
com

--- Comment #1 from Tyler Smith <whitesmith137 at outlook dot com> ---
Not a bug.

The full-expression of the init-declarator `nd` ([intro.execution]/5.4) must be
a constant expression ([dcl.constexpr]/10/3). This "implicit" expression
comprises the prvalue `NewDelete()` (which is the expression that the compiler
is complaining about). As such, it must satisfy the constraints under
[expr.const]/11. Specifically, as a class type, each subobject (i.e. `data_`)
must also satisfy these constraints (11.4); then, as a pointer type, `data_`
must only address either a static-storage object, non-immediate function, or be
null (11.2). Since it instead points to dynamic storage from `new int()`,
`NewDelete()` is not a constant expression.

Furthermore, this full-expression is not even a _core_ constant expression
because its evaluation does not include deallocation of the storage obtained
via `new int()` ([expr.const]/5.17).

The full-expression within the `static_assert` is a valid constant expression
because its evaluation _does_ include the deallocation via `delete data_`.
Here, `NewDelete()` materializes a temporary which is then destroyed at the end
of the full-expression, invoking the destructor doing the deallocation, all as
part of the same evaluation.

(The above references are to the N4861 C++20 draft.)

Reply via email to