Skip to content

Trivial relocatability/replaceability of class with user-provided defaulted destructor #143599

Closed
@jakubjelinek

Description

@jakubjelinek

I've tried to turn the https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2786r13.html#simple-worked-examples examples into a testcase:
https://godbolt.org/z/h4We6c8KM
Trying this with clang and gcc (in that case using _is* traits rather than the _builtin_is_cpp* or _builtin_is* ones), I get similar results (tons of failed assertions, will need to go through that, wonder if it is from some earlier version of the paper not updated afterwards or what) between the two compilers, except for the

struct I { ~I (); };
I::~I () = default;

static_assert (!std::is_trivially_copyable_v <I>, "");
static_assert (!std::is_trivially_relocatable_v <I>, "");
static_assert (!std::is_replaceable_v <I>, "");

testcase in there, where it passes with GCC but the last 2 assertions fail with clang trunk.
My reading of the standard is that I has user-provided destructor and so according to
https://eel.is/c++draft/class.prop#2.3
shouldn't be default-movable and while it is eligible for trivial relocation and eligible for replacement, because it doesn't have the conditional keywords and is not a union, it should be neither trivially relocatable nor replaceable.

BTW, as the appendix says,

struct C {}; struct C replaceable_if_eligible {};

should be valid in C++11 through C++23, but clang trunk rejects that.

@cor3ntin

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions