C++ Logo

std-proposals

Advanced search

Re: Constexpr destructors standard library update omission

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 16 Jul 2020 10:00:22 -0700
On Thursday, 16 July 2020 01:56:02 PDT Maciej Cencora via Std-Proposals wrote:
> Since implementing this is trivial, is there a chance to fix this as a
> defect report?

Pretty sure the answer to this question is "no", even if this is an
unintentional oversight and the change has no impact on existing applications.

Question on constexpr destructors. What happens in this case:

struct S
{
    bool b;
    constexpr S() : b(false) {}
    constexpr ~S() { if (b) abort(); }
};

constinit S s {};
int main()
{
    s.b = true;
}

The constructor for S is constexpr, so that constinit does not need load-time
dynamic initialisation for s. Without the constexpr in the destructor,
constinit would generate static initialisation of s and do a dynamic
registration of its destructor at runtime.

In the presence of that constexpr destructor, S becomes a trivial type. So is
constinit still required to register the dynamic destruction? And if not, why
it it acceptable that abort() isn't called?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

Received on 2020-07-16 12:04:50