https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65071
Bug ID: 65071 Summary: ICE on valid, sizeof...() of template template parameter pack in return type Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: maltsevm at gmail dot com The following (presumably valid) code causes segfault on trunk r220715 and 4.9.2: $ cat ./ice_sizeof.cc template<int N> struct array { int data[N]; }; template<template<typename> class... T1, typename T2> array<sizeof...(T1)> make_array(T1<T2> ...init) { return { 0 }; } template<typename T> struct S { T a; }; auto arr = make_array(S<int>{1}); ====================================================== miyuki@gcc-devel2:~/gcc/test/ice_sizeof$ ../../obj/gcc/cc1plus -std=c++11 ice_sizeof.cc &> bug_report.txt; cat bug_report.txt array<sizeof... (T1)> make_array(T1<T2>...) array<sizeof... (T1)> make_array(T1<T2>...) [with T1 = {S}; T2 = int] void __static_initialization_and_destruction_0(int, int) void _GLOBAL__sub_I_arr() Analyzing compilation unit ice_sizeof.cc: In instantiation of 'array<sizeof... (T1)> make_array(T1<T2>...) [with T1 = {S}; T2 = int]': ice_sizeof.cc:8:22: internal compiler error: tree check: expected class 'type', have 'declaration' (template_decl) in write_CV_qualifiers_for_type, at cp/mangle.c:2154 array<sizeof...(T1)> make_array(T1<T2> ...init) ^ 0xefd737 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*) /home/miyuki/gcc/src/gcc/tree.c:9341 0x7c9e9b tree_class_check(tree_node*, tree_code_class, char const*, int, char const*) /home/miyuki/gcc/src/gcc/tree.h:2969 0x7c9e9b write_CV_qualifiers_for_type /home/miyuki/gcc/src/gcc/cp/mangle.c:2154 0x7d03b3 write_type /home/miyuki/gcc/src/gcc/cp/mangle.c:1876 0x7d07e1 write_type /home/miyuki/gcc/src/gcc/cp/mangle.c:2049 0x7cf5b8 write_template_arg /home/miyuki/gcc/src/gcc/cp/mangle.c:3158 0x7cfcb8 write_template_args /home/miyuki/gcc/src/gcc/cp/mangle.c:2546 0x7ced2a write_name /home/miyuki/gcc/src/gcc/cp/mangle.c:831 0x7d09e6 write_class_enum_type /home/miyuki/gcc/src/gcc/cp/mangle.c:2517 0x7d09e6 write_type /home/miyuki/gcc/src/gcc/cp/mangle.c:1974 0x7d2d04 write_bare_function_type /home/miyuki/gcc/src/gcc/cp/mangle.c:2440 0x7d7b39 mangle_decl_string /home/miyuki/gcc/src/gcc/cp/mangle.c:3411 0x7d7d77 get_mangled_id /home/miyuki/gcc/src/gcc/cp/mangle.c:3433 0x7d7d77 mangle_decl(tree_node*) /home/miyuki/gcc/src/gcc/cp/mangle.c:3478 0xefdd10 decl_assembler_name(tree_node*) /home/miyuki/gcc/src/gcc/tree.c:697 0x910d77 symtab_node::get_comdat_group_id() /home/miyuki/gcc/src/gcc/cgraph.h:207 0x910d77 analyze_functions /home/miyuki/gcc/src/gcc/cgraphunit.c:973 0x9120e5 symbol_table::finalize_compilation_unit() /home/miyuki/gcc/src/gcc/cgraphunit.c:2427 0x6f3037 cp_write_global_declarations() /home/miyuki/gcc/src/gcc/cp/decl2.c:4750 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. ====================================================== GCC 4.9.2 20141030 (Red Hat 4.9.2-5.ac1), i386, also crashes. GCC 4.8.2 20140120 (Red Hat 4.8.2-16) rejects the code with the following error: ./ice_sizeof.cc:8:20: error: template argument 1 is invalid array<sizeof...(T1)> make_array(T1<T2> ...init) clang-3.7 compiles the file without errors. Changing the declaration to "auto make_array_ice(T1<T2> ...init) -> array<sizeof...(T1)>" does not change the behavior, but "auto make_array_ice(T1<T2> ...init) -> array<sizeof...(init)>" gets compiled without errors by all 3 mentioned versions of g++.