This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]