https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79385
Bug ID: 79385 Summary: ICE on (likely) valid C++11 code on x86_64-linux-gnu: Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: su at cs dot ucdavis.edu Target Milestone: --- The code also crashes at least 4.7.x and later, as well as clang 3.5.x and later. Interestingly, if we move enum A < int >::E e; immediately before static_assert (A < int >().f () == 0, "error"); the code compiles fine. $ 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.1/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.1 20170205 (experimental) [trunk revision 245187] (GCC) $ $ g++-trunk -c -std=c++11 small.cpp small.cpp: In instantiation of ‘constexpr int A<T>::f() const [with T = int]’: small.cpp:12:30: required from here small.cpp:10:68: internal compiler error: in tsubst_copy, at cp/pt.c:14451 template < typename T > constexpr int A < T >::f () const { return R; } ^ 0x6faeff tsubst_copy ../../gcc-source-trunk/gcc/cp/pt.c:14451 0x6fdd20 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../gcc-source-trunk/gcc/cp/pt.c:17856 0x6f1337 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:16403 0x6f2b3c tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:15666 0x6f1b33 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:15880 0x6eef94 instantiate_decl(tree_node*, bool, bool) ../../gcc-source-trunk/gcc/cp/pt.c:22819 0x8d1157 cxx_eval_call_expression ../../gcc-source-trunk/gcc/cp/constexpr.c:1490 0x8d2ee3 cxx_eval_constant_expression ../../gcc-source-trunk/gcc/cp/constexpr.c:3957 0x8daa59 cxx_eval_outermost_constant_expr ../../gcc-source-trunk/gcc/cp/constexpr.c:4591 0x8ddf05 maybe_constant_value(tree_node*, tree_node*) ../../gcc-source-trunk/gcc/cp/constexpr.c:4805 0x8b8cf1 cp_fully_fold(tree_node*) ../../gcc-source-trunk/gcc/cp/cp-gimplify.c:1963 0x7f33da cp_build_binary_op(unsigned int, tree_code, tree_node*, tree_node*, int) ../../gcc-source-trunk/gcc/cp/typeck.c:5237 0x6911ba build_new_op_1 ../../gcc-source-trunk/gcc/cp/call.c:5976 0x6922be build_new_op(unsigned int, tree_code, int, tree_node*, tree_node*, tree_node*, tree_node**, int) ../../gcc-source-trunk/gcc/cp/call.c:6021 0x7e3692 build_x_binary_op(unsigned int, tree_code, tree_node*, tree_code, tree_node*, tree_code, tree_node**, int) ../../gcc-source-trunk/gcc/cp/typeck.c:3924 0x7bb9d6 cp_parser_binary_expression ../../gcc-source-trunk/gcc/cp/parser.c:9033 0x7bc130 cp_parser_assignment_expression ../../gcc-source-trunk/gcc/cp/parser.c:9165 0x7bc56a cp_parser_constant_expression ../../gcc-source-trunk/gcc/cp/parser.c:9433 0x7bc64f cp_parser_static_assert ../../gcc-source-trunk/gcc/cp/parser.c:13579 0x7cf919 cp_parser_block_declaration ../../gcc-source-trunk/gcc/cp/parser.c:12590 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 : int; constexpr int f () const; }; enum A < int >::E e; template < typename T > enum A < T >::E : int { R }; template < typename T > constexpr int A < T >::f () const { return R; } static_assert (A < int >().f () == 0, "error");