c++: Fix up mangling of static lambdas [PR108525]
authorJakub Jelinek <jakub@redhat.com>
Wed, 25 Jan 2023 14:13:30 +0000 (15:13 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 25 Jan 2023 14:13:30 +0000 (15:13 +0100)
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.

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
gcc/testsuite/g++.dg/cpp23/static-operator-call5.C

index 62e9f9f..f2cda3b 100644 (file)
@@ -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))
index ae022d0..ecbb843 100644 (file)
@@ -1,3 +1,8 @@
+// PR c++/108525
+// { dg-do compile { target c++23 } }
+
+auto b = [](...) static { return 1; };
+auto foo () { return b (); }
 // PR c++/108526
 // { dg-do compile { target c++23 } }