From: Patrick Palka Date: Sat, 15 Jul 2023 13:47:36 +0000 (-0400) Subject: c++: mangling template-id of unknown template [PR110524] X-Git-Tag: basepoints/gcc-15~7601 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97ceaa110e1607ec8f4f1223200868e1642f3cc7;p=thirdparty%2Fgcc.git c++: mangling template-id of unknown template [PR110524] This fixes a crash when mangling an ADL-enabled call to a template-id naming an unknown template (as per P0846R0). PR c++/110524 gcc/cp/ChangeLog: * mangle.cc (write_expression): Handle TEMPLATE_ID_EXPR whose template is already an IDENTIFIER_NODE. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/fn-template26.C: New test. --- diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index 7dab4e62bc9e..bef0fda6d229 100644 --- a/gcc/cp/mangle.cc +++ b/gcc/cp/mangle.cc @@ -3312,7 +3312,8 @@ write_expression (tree expr) else if (TREE_CODE (expr) == TEMPLATE_ID_EXPR) { tree fn = TREE_OPERAND (expr, 0); - fn = OVL_NAME (fn); + if (!identifier_p (fn)) + fn = OVL_NAME (fn); if (IDENTIFIER_ANY_OP_P (fn)) write_string ("on"); write_unqualified_id (fn); diff --git a/gcc/testsuite/g++.dg/cpp2a/fn-template26.C b/gcc/testsuite/g++.dg/cpp2a/fn-template26.C new file mode 100644 index 000000000000..d4a17eb9bd18 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/fn-template26.C @@ -0,0 +1,16 @@ +// PR c++/110524 +// { dg-do compile { target c++20 } } + +template +auto f(T t) -> decltype(g(t)); + +namespace N { + struct A { }; + template void g(T); +}; + +int main() { + f(N::A{}); +} + +// { dg-final { scan-assembler "_Z1fIN1N1AEEDTcl1gIT_Efp_EES2_" } }