https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70204
Bug ID: 70204 Summary: ICE on x86_64-linux-gnu in non_const_var_error, at cp/constexpr.c:2764 Product: gcc Version: 6.0 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 following (invalid) code causes an ICE when compiled with the current GCC trunk on x86_64-linux-gnu in both 32-bit and 64-bit modes. This is a regression from 5.3.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/6.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 6.0.0 20160311 (experimental) [trunk revision 234134] (GCC) $ $ g++-5.3 -c small.cpp small.cpp: In function ‘void fn1()’: small.cpp:7:9: error: ‘y’ cannot appear in a constant-expression fn1 < y, I > (); ^ $ $ g++-trunk -c small.cpp small.cpp: In function ‘void fn1()’: small.cpp:7:9: error: the value of ‘y’ is not usable in a constant expression fn1 < y, I > (); ^ small.cpp:6:24: note: ‘y’ was not initialized with a constant expression const int x = I * a, y = x; ^ small.cpp: In instantiation of ‘void fn1() [with int N = 0; int I = 0]’: small.cpp:13:17: required from here small.cpp:7:16: error: no matching function for call to ‘fn1()’ fn1 < y, I > (); ~~~~~~~~~~~~~^~ small.cpp:4:6: note: candidate: template<int N, int I> void fn1() void fn1 () ^~~ small.cpp:4:6: note: template argument deduction/substitution failed: small.cpp:7:16: error: the value of ‘y’ is not usable in a constant expression fn1 < y, I > (); ~~~~~~~~~~~~~^~ small.cpp:7:16: internal compiler error: in non_const_var_error, at cp/constexpr.c:2764 0x8440c7 non_const_var_error ../../gcc-source-trunk/gcc/cp/constexpr.c:2764 0x84e21d cxx_eval_constant_expression ../../gcc-source-trunk/gcc/cp/constexpr.c:3336 0x84c9d0 cxx_eval_constant_expression ../../gcc-source-trunk/gcc/cp/constexpr.c:3720 0x852c19 cxx_eval_outermost_constant_expr ../../gcc-source-trunk/gcc/cp/constexpr.c:3939 0x6940a7 convert_nontype_argument ../../gcc-source-trunk/gcc/cp/pt.c:6378 0x6940a7 convert_template_argument ../../gcc-source-trunk/gcc/cp/pt.c:7254 0x6a05eb coerce_template_parms ../../gcc-source-trunk/gcc/cp/pt.c:7715 0x6b90d1 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node* const*, unsigned int, tree_node*, unification_kind_t, int, bool, bool) ../../gcc-source-trunk/gcc/cp/pt.c:17625 0x61588b print_z_candidate ../../gcc-source-trunk/gcc/cp/call.c:3440 0x6174f6 print_z_candidates ../../gcc-source-trunk/gcc/cp/call.c:3510 0x621167 build_new_function_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, int) ../../gcc-source-trunk/gcc/cp/call.c:4120 0x7bba69 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int) ../../gcc-source-trunk/gcc/cp/semantics.c:2453 0x68a3f6 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../gcc-source-trunk/gcc/cp/pt.c:16623 0x67cddf tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:15795 0x67d480 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:15111 0x67c803 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:15097 0x67e320 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-source-trunk/gcc/cp/pt.c:15283 0x67a976 instantiate_decl(tree_node*, int, bool) ../../gcc-source-trunk/gcc/cp/pt.c:22006 0x6c6c42 instantiate_pending_templates(int) ../../gcc-source-trunk/gcc/cp/pt.c:22125 0x70a587 c_parse_final_cleanups() ../../gcc-source-trunk/gcc/cp/decl2.c:4599 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. $ ---------------------------------- int a; template < int N, int I > void fn1 () { const int x = I * a, y = x; fn1 < y, I > (); } int main () { fn1 < 0, 0 > (); return 0; }