C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Constexpr destructors standard library update omission
From: Thiago Macieira (thiago_at_[hidden])
Date: 2020-07-16 16:26:39


On Thursday, 16 July 2020 13:54:24 PDT Maciej Cencora wrote:
> As far as I understand the latest C++ draft, constexpr destructor doesn't
> make the type trivial. It is just that constexpr destructor is allowed to
> be called in constexpr context (while in previous C++ standards only types
> with trivial destructors were allowed in constexpr context).

Sorry, I misspoke. I didn't mean it was a trivial type. I meant it was a
*literal* type.

http://eel.is/c++draft/basic.types#10

Specifically, "a type is a literal type if ... it has a constexpr destructor"
Changed from C++17 that required trivial.

Literal types are required (but not sufficient condition) for constexpr
functions.

> So I guess this would fail to compile, because such a global would still
> require a runtime registration of the destructor during initialization.

I think it would succeed in compiling but, despite the constexpr destructor,
would always emit a dynamic initialiser to destroy this object dynamically. I
think it makes sense, as any non-trivial destructor is necessarily doing
something, so it must be run

I'd like a "don't destroy" marker to go along constinit.

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

STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups