This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2778. Trivial destructor does not imply constant destruction

Section: 7.7  [expr.const]     Status: review     Submitter: Jiang An     Date: 2023-07-27

Consider:

  struct Foo {};
  struct Bar {
    mutable Foo f;
  };
  constexpr Bar b{};     // #1

In C++20, Foo and Bar are literal types, and #1 is well-formed. In C++23, the requirement for the variable b changed to "constant destruction". However, Bar does not have constant destruction, because its mutable member violates 7.7 [expr.const] bullet 5.17:

This is because the mutable member is considered to have its lifetime begin outside of E per 7.7 [expr.const] paragraph 9:

An object a is said to have constant destruction if:

Proposed resolution (reviewed by CWG 2024-03-01):

Change in 7.7 [expr.const] paragraph 10 as follows:

An object a is said to have constant destruction if: