https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71007
Eric Gallager <egallager at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |compile-time-hog, | |diagnostic Status|UNCONFIRMED |NEW Last reconfirmed| |2017-08-21 CC| |egallager at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> --- (In reply to Johannes Schaub from comment #0) > The following is supposed to tell the user that char[0] is an invalid type, > during diagnostic printing. But instead, it infinitely recurses up to > SIZE_MAX or something during printing the diagnostic message, eventually > crashing > > #include <utility> > #include <tuple> > > template<typename T, T ...I> > auto ignore_n(std::integer_sequence<T, I...>) { > return std::make_tuple((I, std::ignore)...); > } > > template<typename... Ts> > auto function(Ts... ts) > -> decltype((std::tuple_cat( > > ignore_n(std::make_index_sequence<sizeof(char[int(sizeof...(Ts))-1])-1> > ()), > std::tuple<double, bool>()) = std::forward_as_tuple(ts...)), > void()) > { > > } > > int main() { > function(2); > function(1, 2, 3); > } > This un-reduced version was taking forever to compile, so I had to kill it before it could crash: $ /usr/local/bin/g++ -c -Wall -Wextra -pedantic -time -ftime-report 71007.cc 71007.cc: In function ‘int main()’: 71007.cc:19:12: error: no matching function for call to ‘function(int)’ function(2); ^ 71007.cc:10:6: note: candidate: ‘template<class ... Ts> decltype ((std::tuple_cat(ignore_n(typename std::_Make_integer_sequence<long unsigned int, sizeof (char[int(sizeof ... (Ts ...)) - 1]) - 1, typename std::_Build_index_tuple<sizeof (char[int(sizeof ... (Ts ...)) - 1]) - 1>::__type>::make_index_sequence()), std::tuple<double, bool>())= std::forward_as_tuple(function::ts ...), void())) function(Ts ...)’ auto function(Ts... ts) ^~~~~~~~ 71007.cc:10:6: note: template argument deduction/substitution failed: 71007.cc: In substitution of ‘template<class ... Ts> decltype ((std::tuple_cat(ignore_n(typename std::_Make_integer_sequence<long unsigned int, sizeof (char[int(sizeof ... (Ts ...)) - 1]) - 1, typename std::_Build_index_tuple<sizeof (char[int(sizeof ... (Ts ...)) - 1]) - 1>::__type>::make_index_sequence()), std::tuple<double, bool>())= std::forward_as_tuple(function::ts ...), void())) function(Ts ...) [with Ts = {int}]’: 71007.cc:19:12: required from here 71007.cc:12:42: warning: ISO C++ forbids zero-size array [-Wpedantic] ignore_n(std::make_index_sequence<sizeof(char[int(sizeof...(Ts))-1])-1> ()), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^C $ (In reply to Johannes Schaub from comment #1) > Sorry, forgot to actually add the code of the reduced testcase: > > template<int N, typename T = char[N-1]> > void f(char(&)[N]) > { } > > int main() { > char x[1]; > f(x); > } Confirmed: $ /usr/local/bin/g++ -c -Wall -Wextra -pedantic 71007_reduced.cc 71007_reduced.cc: In function ‘int main()’: 71007_reduced.cc:7:4: error: no matching function for call to ‘f(char [1])’ f(x); ^ 71007_reduced.cc:2:6: note: candidate: ‘template<int N, class T> void f(char (&)[N])’ void f(char(&)[N]) ^ 71007_reduced.cc:2:6: note: template argument deduction/substitution failed: 71007_reduced.cc:1:17: warning: ISO C++ forbids zero-size array [-Wpedantic] template<int N, typename T = char[N-1]> ^~~~~~~~ $ Weird that the underlining here points to the typename before T rather than the actual array size.