http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57240
Bug ID: 57240 Summary: decltype() on a template non-type parameter causes "internal compiler error" Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: scottbaldwin at gmail dot com GCC 4.8.x (4.8.0 and 4.8.1-20130427) have an "internal compiler error" when decltype()'s argument is a template non-type parameter. The following code is a simple demo of the bug. The demo also includes a "workaround" to show the issue does not occur when the non-type parameter is "converted" to an equivalent value (i.e., something that is no longer a template non-type parameter). --- template<typename _fptype> struct FuncPointerType { // wrap a function pointer type (for demo purposes) typedef _fptype type; }; void some_func() {} // some function w/ signature of void(void) template< void(*func_ptr)(void) > void bug_demo() { // crashes w/ "internal compiler error" using FPT = FuncPointerType< decltype(func_ptr) >; // crashes compiler in 4.8.0/4.8.1 (works in 4.7.2) // workaround (if uncommented): pass decltype() an equivalent value that is not a template nontype parameter //auto fp = func_ptr; //using FPT = FuncPointerType< decltype(fp) >; // works fine now // next line should output "[1]" (if correct) std::cout << "[" << std::is_same<typename FPT::type, void(*)(void)>::value << "]" << std::endl; } int main() { bug_demo<some_func>(); return 0; } ------------ [gcc 4.8.1] ------------ make[1]: compiling [sandbox_cpp11.cpp] (gcc 4.8.1 20130427) g++ -c sandbox_cpp11.cpp -o dbg-mt/sandbox_cpp11.o -pthread -Wall -Werror -Wno-unused -Wno-unused-variable -std=c++11 -rdynamic -g3 -O0 -m64 -D__64BIT__ -I./dbg-mt -I. -I. sandbox_cpp11.cpp: In instantiation of ‘void gcc_bug_demo_1::bug_demo() [with void (* func_ptr)() = gcc_bug_demo_1::some_func]’: sandbox_cpp11.cpp:71:23: required from here sandbox_cpp11.cpp:57:52: internal compiler error: in finish_decltype_type, at cp/semantics.c:5373 using FPT = FuncPointerType< decltype(func_ptr) >; // crashes compiler in 4.8.0/4.8.1 (works in 4.7.2) ^ 0x5a3680 finish_decltype_type(tree_node*, bool, int) ../../srcdir/gcc/cp/semantics.c:5373 0x5157d0 tsubst(tree_node*, tree_node*, int, tree_node*) ../../srcdir/gcc/cp/pt.c:11812 0x51b352 tsubst_template_args ../../srcdir/gcc/cp/pt.c:9630 0x522010 tsubst_aggr_type ../../srcdir/gcc/cp/pt.c:9827 0x515d45 tsubst(tree_node*, tree_node*, int, tree_node*) ../../srcdir/gcc/cp/pt.c:11190 0x523d36 tsubst_decl ../../srcdir/gcc/cp/pt.c:10648 0x516087 tsubst(tree_node*, tree_node*, int, tree_node*) ../../srcdir/gcc/cp/pt.c:11111 0x518eea tsubst_expr ../../srcdir/gcc/cp/pt.c:12894 0x518cdc tsubst_expr ../../srcdir/gcc/cp/pt.c:12843 0x518f80 tsubst_expr ../../srcdir/gcc/cp/pt.c:13033 0x518433 instantiate_decl(tree_node*, int, bool) ../../srcdir/gcc/cp/pt.c:18910 0x52cb8b instantiate_pending_templates(int) ../../srcdir/gcc/cp/pt.c:19009 0x5445bf cp_write_global_declarations() ../../srcdir/gcc/cp/decl2.c:4043 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. make[1]: *** [dbg-mt/sandbox_cpp11.o] Error 1 make: *** [objs] Error 2 ------------ [gcc 4.8.0] ------------ make[1]: compiling [sandbox_cpp11.cpp] (gcc 4.8.0) g++ -c sandbox_cpp11.cpp -o dbg-mt/sandbox_cpp11.o -pthread -Wall -Werror -Wno-unused -Wno-unused-variable -std=c++11 -rdynamic -g3 -O0 -m64 -D__64BIT__ -I./dbg-mt -I. -I. sandbox_cpp11.cpp: In instantiation of ‘void gcc_bug_demo_1::bug_demo() [with void (* func_ptr)() = gcc_bug_demo_1::some_func]’: sandbox_cpp11.cpp:71:23: required from here sandbox_cpp11.cpp:57:52: internal compiler error: in finish_decltype_type, at cp/semantics.c:5365 using FPT = FuncPointerType< decltype(func_ptr) >; // crashes compiler in 4.8.0/4.8.1 (works in 4.7.2) ^ 0x5a2ac0 finish_decltype_type(tree_node*, bool, int) ../../srcdir/gcc/cp/semantics.c:5365 0x51e50c tsubst(tree_node*, tree_node*, int, tree_node*) ../../srcdir/gcc/cp/pt.c:11772 0x5217c2 tsubst_template_args ../../srcdir/gcc/cp/pt.c:9607 0x524000 tsubst_aggr_type ../../srcdir/gcc/cp/pt.c:9804 0x51de20 tsubst(tree_node*, tree_node*, int, tree_node*) ../../srcdir/gcc/cp/pt.c:11160 0x51cb16 tsubst_decl ../../srcdir/gcc/cp/pt.c:10625 0x51e157 tsubst(tree_node*, tree_node*, int, tree_node*) ../../srcdir/gcc/cp/pt.c:11081 0x51927a tsubst_expr ../../srcdir/gcc/cp/pt.c:12853 0x51906c tsubst_expr ../../srcdir/gcc/cp/pt.c:12802 0x519310 tsubst_expr ../../srcdir/gcc/cp/pt.c:12992 0x5187c3 instantiate_decl(tree_node*, int, bool) ../../srcdir/gcc/cp/pt.c:18854 0x52d40b instantiate_pending_templates(int) ../../srcdir/gcc/cp/pt.c:18953 0x54416f cp_write_global_declarations() ../../srcdir/gcc/cp/decl2.c:4025 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. make[1]: *** [dbg-mt/sandbox_cpp11.o] Error 1 make: *** [objs] Error 2