Bug 54998 - Internal compiler error with union member initialization using default constructor
Summary: Internal compiler error with union member initialization using default constr...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-20 12:25 UTC by tobias.anderberg
Modified: 2013-07-04 10:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.9.0
Known to fail: 4.8.1
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tobias.anderberg 2012-10-20 12:25:33 UTC
class Foo {
public:
private:
    static const int kRows = 4;
    static const int kCols = 4;

    union {
        float m_n[kRows][kCols];
        float m_m[kRows * kCols] = {
            1.0f, 0.0f, 0.0f, 0.0f,
            0.0f, 1.0f, 0.0f, 0.0f,
            0.0f, 0.0f, 1.0f, 0.0f,
            0.0f, 0.0f, 0.0f, 1.0f
        };
    };
};

int main()
{
    Foo myFoo;
    return 0;
}

Compile: g++ -std=c++11 foo.cc

Result:

foo.cc: In constructor ‘constexpr Foo::Foo()’:
foo.cc:1:7: internal compiler error: in cx_check_missing_mem_inits, at cp/semantics.c:6166
 class Foo {
       ^

foo.cc:1:7: internal compiler error: Abort trap: 6
g++: internal compiler error: Abort trap: 6 (program cc1plus)
Abort trap: 6

System:
Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64

GCC build command: ./configure --enable-languages=c,c++

g++ --version
g++ (GCC) 4.8.0 20121020 (experimental)

Additional notes:
By either naming the union, or supplying a default constructor the sample compiles.
Comment 1 Paolo Carlini 2013-07-04 10:11:54 UTC
This is fixed in mainline. I'm adding the testcase and closing the bug.
Comment 2 Paolo Carlini 2013-07-04 10:27:29 UTC
Done.