https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70054
Bug ID: 70054 Summary: GCC 6 gives a strict-aliasing warning on use of std::aligned_storage Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: tavianator at gmail dot com Target Milestone: --- GCC 6 warns on this code; GCC 5 didn't. boost::container::string uses this pattern as part of its SSO implementation, so I'm getting a lot of new warnings with GCC 6 as a result. As well, I'm seeing what appears to be a miscompilation as a result, but I haven't reduced that yet. $ cat foo.cpp #include <type_traits> struct foo { std::aligned_storage<sizeof(long), alignof(long)>::type raw; long& cooked() { return *static_cast<long*>(static_cast<void*>(&raw)); } }; $ g++ -O2 -Wall -c foo.cpp foo.cpp: In member function ‘long int& foo::cooked()’: foo.cpp:7:56: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] return *static_cast<long*>(static_cast<void*>(&raw));