https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68679
Bug ID: 68679 Summary: gcc-5.2.1 ICE in C++11 anon union of structs with template fns, OK in gcc <= 4.9.3 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ejkruus at gmail dot com Target Milestone: --- Created attachment 36899 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36899&action=edit ICE in union of struct with functions, no-headers The following code (also attached) causes an ICE in gcc-5.2.1, but was acceptable for several gcc <= 4.9.3. Keeping two of the three struct cases was often OK, but adding third 'dimN' into the union seemed to always be a bad thing. System: Ubuntu 15.10, x86_64 cpu family : 6 model : 30 model name : Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz /////////////////// terminal kruus@borg:~/w/milde$ g++ --version g++ (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. kruus@borg:~/w/milde$ gcc-5 -std=c++11 -c a.cpp -o a.o a.cpp: In instantiation of ‘uint_least32_t Hdr::<anonymous union>::<anonymous struct>::operator[](IDX) const [with IDX = unsigned int; uint_least32_t = unsigned int]’: a.cpp:27:32: required from here a.cpp:18:45: internal compiler error: in structural_comptypes, at cp/typeck.c:1197 template<typename IDX> uint_least32_t operator[](IDX const i) const { ^ ... kruus@borg:~/w/milde$ gcc-5 -std=c++11 -g -c a.cpp -o a.o a.cpp: In instantiation of ‘uint_least32_t Hdr::<anonymous union>::<anonymous struct>::operator[](IDX) const [with IDX = unsigned int; uint_least32_t = unsigned int]’: a.cpp:26:32: required from here a.cpp:14:45: sorry, unimplemented: use of ‘<invalid tree code>’ in template template<typename IDX> uint_least32_t operator[](IDX const i) const { ^ ... ////////////////////// sample code typedef unsigned u32; typedef unsigned short u16; typedef unsigned char u8; typedef struct { union { // seems to work with two of them, but adding the third causes ICE? struct { u32 d[4]; template<typename IDX> u32 operator[](IDX const i) const { return d[i]; } } dim0; struct { u16 d[8]; template<typename IDX> u32 operator[](IDX const i) const { return d[i]; } } dim1; struct { u8 d[16]; template<typename IDX> u32 operator[](IDX const i) const { return d[i]; } } dim2; /** \c dims(fmt,i) returns the \c i'th item of \c dims in format \c fmt */ u32 operator()(u8 fmt, u32 idx) const { u32 ret=0U; switch(fmt){ case(0): ret = dim0[idx]; break; case(1): ret = dim1[idx]; break; case(2): ret = dim2[idx]; break; default: ; } return ret; } } dims; u8 fmt; ///< dimension encoding fmt } Hdr; int main(int,char**){ return 0; }