public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "t-gcc-bugzilla at snowelm dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/56215] New: Cannot create constexpr struct with unnamed unions Date: Wed, 06 Feb 2013 04:05:00 -0000 [thread overview] Message-ID: <bug-56215-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56215 Bug #: 56215 Summary: Cannot create constexpr struct with unnamed unions Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: t-gcc-bugzilla@snowelm.com Similar to PR c++/51675, but the trunk GCC fails to compile the following code: ------ struct foo { union { int x; short y; }; constexpr foo() : x( 0 ) { } }; ------ $ g++ --std=c++11 hoge.cpp hoge.cpp: In constructor ‘constexpr foo::foo()’: hoge.cpp:7:33: error: uninitialized member ‘foo::<anonymous>’ in ‘constexpr’ constructor constexpr foo() : x( 0 ) { } ^ What I actually want to do is a specialization of std::pair to provide efficient comparison. Since this requires an unnamed struct within an unnamed union, and the bug seems very sensitive to details like that, I put the code too. GCC trunk also fails compiling the following. ------ #include <utility> #include <cstdint> namespace std { template <> struct pair< uint32_t, uint32_t > { union { struct { uint32_t first; uint32_t second; }; uint64_t paired; }; constexpr pair() : paired( ) { } constexpr pair(uint32_t a, uint32_t b) : first(a), second(b) { } }; constexpr bool operator== ( pair<uint32_t,uint32_t> a, pair<uint32_t,uint32_t> b ) { return a.paired == b.paired; } constexpr bool operator< ( pair<uint32_t,uint32_t> a, pair<uint32_t,uint32_t> b ) { // only for little endian return ((a.paired<<32)|(a.paired>>32)) < ((b.paired<<32)|(b.paired>>32)); } } // namespace std::pair<uint32_t,uint32_t> x(1, 2); ------
next reply other threads:[~2013-02-06 4:05 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-02-06 4:05 t-gcc-bugzilla at snowelm dot com [this message] 2013-02-06 9:34 ` [Bug c++/56215] " paolo.carlini at oracle dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-56215-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).