https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113407
Bug ID: 113407 Summary: internal_error with const char* as non-type template parameter with index parameter pack in fold expression Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: miro.palmu at helsinki dot fi Target Milestone: --- Created attachment 57093 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57093&action=edit The preprocessed source from -freport-bug I have piece of code that should not compile due to parameter pack not located at the end of template parameter list. However gcc 14.0.1 20240115 gives internal compiler error while gcc 13 and earlier do not give internal errors and the compilation fails gracefully. Here is the code: ``` // index_sequence implementation: template <int...> struct index_sequence; template <int... I> struct index_sequence{ }; template <int... I> struct index_sequence_helper; template <int... I> struct index_sequence_helper <0, I...> { using type = index_sequence<I...>; }; template <int n, int... I> struct index_sequence_helper <n, I...> : public index_sequence_helper<n - 1, n - 1, I...> { }; template <int n> auto make_index_sequence() -> index_sequence_helper<n>::type {}; // Helpers: template <typename... T, int I> void inner_func(char) {} template <typename... T, int I> struct Foo {}; constexpr char global_string[] = "abc"; template<const char * C, typename... A> bool func() { return []<int... I>(index_sequence<I...>) { return (inner_func<Foo<A..., I>>(C[I]), ...); }(make_index_sequence<sizeof...(A)>{}); } int main() { func<global_string>(); } ``` It also seems that the const char* being non-type template parameter and not a normal function parameter is important for the internal_error. Here is the error message (compile command: g++ error.cpp): ``` error.cpp:19:31: error: need ‘typename’ before ‘index_sequence_helper<n>::type’ because ‘index_sequence_helper<n>’ is a dependent scope 19 | auto make_index_sequence() -> index_sequence_helper<n>::type {}; | ^~~~~~~~~~~~~~~~~~~~~~~~ | typename error.cpp:26:11: error: parameter pack ‘T’ must be at the end of the template parameter list 26 | template <typename... T, int I> | ^~~~~~~~ error.cpp: In lambda function: error.cpp:35:38: note: so any instantiation with a non-empty parameter pack would be ill-formed 35 | return (inner_func<Foo<A..., I>>(C[I]), ...); | ^ error.cpp: In function ‘bool func()’: error.cpp:36:7: error: ‘make_index_sequence’ was not declared in this scope; did you mean ‘index_sequence’? 36 | }(make_index_sequence<sizeof...(A)>{}); | ^~~~~~~~~~~~~~~~~~~ | index_sequence error.cpp:36:40: error: expected primary-expression before ‘{’ token 36 | }(make_index_sequence<sizeof...(A)>{}); | ^ error.cpp: In instantiation of ‘bool func() [with const char* C = (& global_string); A = {}]’: error.cpp:40:24: required from here error.cpp:36:40: error: 40 | func<global_string>(); error.cpp:36:40: error: | ~~~~~~~~~~~~~~~~~~~^~ error.cpp:35:47: internal compiler error: tree check: expected type_pack_expansion or expr_pack_expansion, have error_mark in tsubst_pack_expansion, at cp/pt.cc:13632 35 | return (inner_func<Foo<A..., I>>(C[I]), ...); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~ 0x951506 tree_check_failed(tree_node const*, char const*, int, char const*, ...) .././../gcc/tree.cc:8952 0x7edbaf tree_check2(tree_node*, char const*, int, char const*, tree_code, tree_code) .././../gcc/tree.h:3631 0x7edbaf tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*) .././../gcc/cp/pt.cc:13632 0xc784c4 tsubst_fold_expr_pack .././../gcc/cp/pt.cc:13043 0xc784c4 tsubst_unary_right_fold .././../gcc/cp/pt.cc:13159 0xc5994a tsubst_expr(tree_node*, tree_node*, int, tree_node*) .././../gcc/cp/pt.cc:21547 0xc68147 tsubst_stmt .././../gcc/cp/pt.cc:19384 0xc69108 tsubst_stmt .././../gcc/cp/pt.cc:18351 0xc68d72 tsubst_stmt .././../gcc/cp/pt.cc:18714 0xc7e4d0 tsubst_stmt .././../gcc/cp/pt.cc:18327 0xc7e4d0 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*) .././../gcc/cp/pt.cc:19732 0xc5b944 tsubst_expr(tree_node*, tree_node*, int, tree_node*) .././../gcc/cp/pt.cc:21629 0xc58482 tsubst_expr(tree_node*, tree_node*, int, tree_node*) .././../gcc/cp/pt.cc:20670 0xc68147 tsubst_stmt .././../gcc/cp/pt.cc:19384 0xc69108 tsubst_stmt .././../gcc/cp/pt.cc:18351 0xc6918f tsubst_stmt .././../gcc/cp/pt.cc:18327 0xc6918f tsubst_stmt .././../gcc/cp/pt.cc:18341 0xc68d72 tsubst_stmt .././../gcc/cp/pt.cc:18714 0xc66ea2 tsubst_stmt .././../gcc/cp/pt.cc:18327 0xc66ea2 instantiate_body .././../gcc/cp/pt.cc:26974 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. ```