Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 13?
-- >8 -- 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. --- gcc/cp/mangle.cc | 3 ++- gcc/testsuite/g++.dg/cpp2a/fn-template26.C | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/fn-template26.C diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc index 7dab4e62bc9..bef0fda6d22 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 00000000000..d4a17eb9bd1 --- /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<class T> +auto f(T t) -> decltype(g<T>(t)); + +namespace N { + struct A { }; + template<class T> void g(T); +}; + +int main() { + f(N::A{}); +} + +// { dg-final { scan-assembler "_Z1fIN1N1AEEDTcl1gIT_Efp_EES2_" } } -- 2.41.0.327.gaa9166bcc0