public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: mangling template-id of unknown template [PR110524]
@ 2023-07-13 13:20 Patrick Palka
  2023-07-14 22:24 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-07-13 13:20 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: mangling template-id of unknown template [PR110524]
  2023-07-13 13:20 [PATCH] c++: mangling template-id of unknown template [PR110524] Patrick Palka
@ 2023-07-14 22:24 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-07-14 22:24 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 7/13/23 09:20, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
> for trunk and perhaps 13?

OK for both.

> -- >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_" } }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-14 22:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-13 13:20 [PATCH] c++: mangling template-id of unknown template [PR110524] Patrick Palka
2023-07-14 22:24 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).