This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/51675] New: [C++11][New in 4.7] Cannot create constexpr unions


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

             Bug #: 51675
           Summary: [C++11][New in 4.7] Cannot create constexpr unions
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: classixretrox@gmail.com


union foo
{
    int x = 0;
    short y;

    constexpr foo() = default;
};

This code compiles under GCC 4.6, however, not GCC 4.7.  It works if I remove
the constexpr keyword.

Output of GCC:
test.cc:6:12: error: explicitly defaulted function âconstexpr foo::foo()â
cannot be declared as constexpr because the implicit declaration is not
constexpr:
test.cc:4:8: note: defaulted default constructor does not initialize âshort int
foo::yâ

If I provide only one initialization, it tells me that the others are
initialized.  If I initialize the others, it tells me that I can't initialize
more than one.  It essentially prevents the creation of constexpr unions.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]