The following C++11 code causes an ICE when compiled with the current GCC trunk on x86_64-linux-gnu in both 32-bit and 64-bit modes. It also affects older versions at least as early as 4.6.x. $ g++-trunk -v Using built-in specs. COLLECT_GCC=g++-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto --prefix=/usr/local/gcc-trunk --disable-bootstrap Thread model: posix gcc version 7.0.0 20160625 (experimental) [trunk revision 237780] (GCC) $ $ g++-trunk -c -std=c++11 small.cpp small.cpp: In instantiation of ‘A<T>::E A<T>::h() [with T = int]’: small.cpp:8:23: required from here small.cpp:14:10: internal compiler error: in tsubst_copy, at cp/pt.c:14010 return e; ^ 0x6dfcdc tsubst_copy ../../gcc-source-trunk/gcc/cp/pt.c:14010 0x6e2906 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../gcc-source-trunk/gcc/cp/pt.c:17243 0x6d68ff tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:15868 0x6d6f75 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:15176 0x6d7e30 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:15351 0x6d4835 instantiate_decl(tree_node*, int, bool) ../../gcc-source-trunk/gcc/cp/pt.c:22095 0x721512 instantiate_pending_templates(int) ../../gcc-source-trunk/gcc/cp/pt.c:22214 0x764645 c_parse_final_cleanups() ../../gcc-source-trunk/gcc/cp/decl2.c:4600 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. $ ---------------------------------------------------------- template < typename T > struct A { enum E : T; E h (); }; A < int > a; A < int >::E b = a.h (); template < typename T > enum A < T >::E : T { e }; template < typename T > typename A < T >::E A < T >::h () { return e; }
Started with r165935.
Related to http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1485 which is still in drafting. Discussion at the October 2012 meeting suggested that an unscoped opaque enum declaration should be ill-formed.
GCC 4.9 branch is being closed
GCC 5 branch is being closed
This seems fixed in trunk, we simply reject the code without ICEing. While reviewing this bug I noticed once more the nit that -Wreturn-type enabled by default means that in such cases we emit a redundant warning: 71662.C:14:10: error: ‘e’ was not declared in this scope return e; ^ 71662.C: In instantiation of ‘A<T>::E A<T>::h() [with T = int]’: 71662.C:8:23: required from here 71662.C:15:1: warning: no return statement in function returning non-void [-Wreturn-type] but that seems an unrelated issue, really. Thus I mean to commit the testcase and remove the 8 Regression marker.
Author: paolo Date: Wed Feb 7 09:35:10 2018 New Revision: 257439 URL: https://gcc.gnu.org/viewcvs?rev=257439&root=gcc&view=rev Log: 2018-02-07 Paolo Carlini <paolo.carlini@oracle.com> PR c++/71662 * g++.dg/cpp0x/scoped_enum7.C: New. Added: trunk/gcc/testsuite/g++.dg/cpp0x/scoped_enum7.C Modified: trunk/gcc/testsuite/ChangeLog
GCC 6 branch is being closed
Fixed in GCC8.