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 middle-end/77295] missed optimisation when copying/moving union members


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

--- Comment #2 from Avi Kivity <avi@cloudius-systems.com> ---
Typically, the code is a template:

template <typename T, typename U>
struct discriminated_union {
    unsigned which;
    union {
        T v1;
        U v2;
    };
};


If either T or U have non-trivial copy/move constructors, then you can't
copy/move the union; you have to copy/move a member.

I guess a template specialization for the case where both are PODs can be used
as a work-around.

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