This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/77295] missed optimisation when copying/moving union members
- From: "avi at cloudius-systems dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 19 Aug 2016 07:19:50 +0000
- Subject: [Bug middle-end/77295] missed optimisation when copying/moving union members
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
- References: <bug-77295-4@http.gcc.gnu.org/bugzilla/>
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.