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.

Reply via email to