This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/87521] [C++][ABI] Tail padding not reused for non POD struct with defaulted/deleted special member function as per Itanium ABI on x86-64
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 14 Nov 2018 17:30:22 +0000
- Subject: [Bug c++/87521] [C++][ABI] Tail padding not reused for non POD struct with defaulted/deleted special member function as per Itanium ABI on x86-64
- Auto-submitted: auto-generated
- References: <bug-87521-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87521
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
What really matters here is triviality of the destructor, and that isn't
affected by the user-declared defaulted dtor.
Clang fails this test, because memcpy overwrites the tail padding:
#include <type_traits>
#include <cstring>
#include <cassert>
struct Base {
unsigned x;
short y;
~Base() = default;
void set(const Base& b);
};
void Base::set(const Base& b) {
static_assert(std::is_trivially_copyable<Base>::value,"");
std::memcpy(this, &b, sizeof(Base));
}
struct Der : Base {
short z;
};
int i[] = { sizeof(Base), sizeof(Der) };
int main()
{
Der d;
d.z = 99;
Base b{};
d.set(b);
assert(d.z == 99);
}
I think GCC is correct here.