c++: Fix up mangling of static lambdas [PR108525]

Message ID Y9BnmXCZtTgjby2V@tucnak
State New
Headers
Series c++: Fix up mangling of static lambdas [PR108525] |

Commit Message

Jakub Jelinek Jan. 24, 2023, 11:19 p.m. UTC
  Hi!

Before the P1169R4 changes, operator () of a lambda was
always a method, so it was fine to pass method_p = 1 unconditionally,
but it isn't always the case, so this patch adds a check for whether
it is a method or nor.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-01-25  Jakub Jelinek  <jakub@redhat.com>

	PR c++/108525
	* mangle.cc (write_closure_type_name): Don't assume all
	lambda operator() fns are methods.

	* g++.dg/cpp23/static-operator-call5.C: New test.


	Jakub
  

Comments

Jason Merrill Jan. 25, 2023, 2:08 p.m. UTC | #1
On 1/24/23 18:19, Jakub Jelinek wrote:
> Hi!
> 
> Before the P1169R4 changes, operator () of a lambda was
> always a method, so it was fine to pass method_p = 1 unconditionally,
> but it isn't always the case, so this patch adds a check for whether
> it is a method or nor.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 2023-01-25  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/108525
> 	* mangle.cc (write_closure_type_name): Don't assume all
> 	lambda operator() fns are methods.
> 
> 	* g++.dg/cpp23/static-operator-call5.C: New test.
> 
> --- gcc/cp/mangle.cc.jj	2023-01-16 11:52:16.000000000 +0100
> +++ gcc/cp/mangle.cc	2023-01-24 18:59:09.335156301 +0100
> @@ -1816,7 +1816,7 @@ write_closure_type_name (const tree type
>         if (abi_warn_or_compat_version_crosses (18))
>   	G.need_abi_warning = true;
>   
> -  write_method_parms (parms, /*method_p=*/1, fn);
> +  write_method_parms (parms, TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE, fn);
>     write_char ('E');
>     if ((LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda)
>          != LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda))
> --- gcc/testsuite/g++.dg/cpp23/static-operator-call5.C.jj	2023-01-24 19:03:21.770469929 +0100
> +++ gcc/testsuite/g++.dg/cpp23/static-operator-call5.C	2023-01-24 19:02:45.224003615 +0100
> @@ -0,0 +1,5 @@
> +// PR c++/108525
> +// { dg-do compile { target c++23 } }
> +
> +auto b = [](...) static { return 1; };
> +auto foo () { return b (); }
> 
> 	Jakub
>
  

Patch

--- gcc/cp/mangle.cc.jj	2023-01-16 11:52:16.000000000 +0100
+++ gcc/cp/mangle.cc	2023-01-24 18:59:09.335156301 +0100
@@ -1816,7 +1816,7 @@  write_closure_type_name (const tree type
       if (abi_warn_or_compat_version_crosses (18))
 	G.need_abi_warning = true;
 
-  write_method_parms (parms, /*method_p=*/1, fn);
+  write_method_parms (parms, TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE, fn);
   write_char ('E');
   if ((LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda)
        != LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda))
--- gcc/testsuite/g++.dg/cpp23/static-operator-call5.C.jj	2023-01-24 19:03:21.770469929 +0100
+++ gcc/testsuite/g++.dg/cpp23/static-operator-call5.C	2023-01-24 19:02:45.224003615 +0100
@@ -0,0 +1,5 @@ 
+// PR c++/108525
+// { dg-do compile { target c++23 } }
+
+auto b = [](...) static { return 1; };
+auto foo () { return b (); }