public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56215] New: Cannot create constexpr struct with unnamed unions
@ 2013-02-06  4:05 t-gcc-bugzilla at snowelm dot com
  2013-02-06  9:34 ` [Bug c++/56215] " paolo.carlini at oracle dot com
  0 siblings, 1 reply; 2+ messages in thread
From: t-gcc-bugzilla at snowelm dot com @ 2013-02-06  4:05 UTC (permalink / raw)
  To: gcc-bugs


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);
------


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/56215] Cannot create constexpr struct with unnamed unions
  2013-02-06  4:05 [Bug c++/56215] New: Cannot create constexpr struct with unnamed unions t-gcc-bugzilla at snowelm dot com
@ 2013-02-06  9:34 ` paolo.carlini at oracle dot com
  0 siblings, 0 replies; 2+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-06  9:34 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56215

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-06 09:34:07 UTC ---
Dup.

*** This bug has been marked as a duplicate of bug 54922 ***


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-02-06  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-06  4:05 [Bug c++/56215] New: Cannot create constexpr struct with unnamed unions t-gcc-bugzilla at snowelm dot com
2013-02-06  9:34 ` [Bug c++/56215] " paolo.carlini at oracle dot com

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).