[Bug c++/65816] Constructor delegation does not perform zero-initialization

Casey at Carter dot net gcc-bugzilla@gcc.gnu.org
Wed May 23 17:38:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65816

Casey Carter <Casey at Carter dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Casey at Carter dot net

--- Comment #3 from Casey Carter <Casey at Carter dot net> ---
I ran across an almost identical case, but involving a base subobject which
isn't properly zero-initialized rather than the member subobject case in
comment 1:

    void* operator new(decltype(sizeof(int)), void* ptr) {
        return ptr;
    }

    struct item { int data; };

    struct collector : item {
        collector() = default;
        collector(int) {}
    };

    struct tuple : collector {
        tuple() : collector{} {}
    };

    int main() {
        alignas(tuple) unsigned char space[sizeof(tuple)];
        for (auto& c : space) c = 0xff;

        auto ptr = ::new(&space) tuple;
        int& i = static_cast<item&>(*ptr).data;
        if (i != 0) __builtin_abort();
    }

Default-initialization of `tuple` invokes its constructor, which
value-initializes its `collector` base subobject, which should zero-initialize
`collector`'s `item` base subobject.


More information about the Gcc-bugs mailing list