[Bug middle-end/77295] missed optimisation when copying/moving union members
avi@cloudius-systems.com
gcc-bugzilla@gcc.gnu.org
Fri Aug 19 07:20:00 GMT 2016
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.
More information about the Gcc-bugs
mailing list