https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115616
Bug ID: 115616 Summary: Friend-injecting a template function causes an ICE if you inject after trying to instantiate that function Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: iamsupermouse at mail dot ru Target Milestone: --- The following causes an internal compiler error in GCC 14 and trunk: https://gcc.godbolt.org/z/z9PWhWvzh Same bug in Clang: https://github.com/llvm/llvm-project/issues/96485 MSVC compiles this successfully and calls `bar<10,20>()`. template <int X, int Y> void bar() {} template <typename T> struct Reader { template <int X> friend void foo(Reader<T>); }; template <typename T, int Y> struct Writer { template <int X> friend void foo(Reader<T>) {bar<X, Y>();} }; int main() { foo<10>(Reader<int>{}); Writer<int, 20>{}; } GCC says: (this is trunk, v14 just says "segmentation fault") <source>: In instantiation of 'void foo(Reader<T>) [with int X = 10; T = int; int Y = <missing>]': <source>:19:12: required from here 19 | foo<10>(Reader<int>{}); | ~~~~~~~^~~~~~~~~~~~~~~ <source>:14:33: internal compiler error: tree check: accessed elt 2 of 'tree_vec' with 1 elts in tsubst, at cp/pt.cc:16362 14 | friend void foo(Reader<T>) {bar<X, Y>();} | ^~~~~~~~~ 0x26cfe8c internal_error(char const*, ...) ???:0 0x97a4bb tree_vec_elt_check_failed(int, int, char const*, int, char const*) ???:0 0xcbc689 tsubst_template_args(tree_node*, tree_node*, int, tree_node*) ???:0 0xcabce3 instantiate_decl(tree_node*, bool, bool) ???:0 0xcd625b instantiate_pending_templates(int) ???:0 0xb6e830 c_parse_final_cleanups() ???:0 0xdcad68 c_common_parse_file() ???:0