]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: generic lambda, implicit 'this' capture, xobj memfn [PR119038]
authorPatrick Palka <ppalka@redhat.com>
Fri, 28 Feb 2025 15:56:49 +0000 (10:56 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 28 Feb 2025 15:56:49 +0000 (10:56 -0500)
When a generic lambda calls an overload set containing an iobj member
function we speculatively capture 'this'.  We need to do the same
for an xobj member function.

PR c++/119038

gcc/cp/ChangeLog:

* lambda.cc (maybe_generic_this_capture): Consider xobj
member functions as well, not just iobj.  Update function
comment.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/explicit-obj-lambda15.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/lambda.cc
gcc/testsuite/g++.dg/cpp23/explicit-obj-lambda15.C [new file with mode: 0644]

index 09898f6746caf74b2c7ddbfa16ede425aff77809..da075b988059ac9b6cbc5fab2c79d25fb01cd616 100644 (file)
@@ -971,9 +971,8 @@ maybe_resolve_dummy (tree object, bool add_capture_p)
 /* When parsing a generic lambda containing an argument-dependent
    member function call we defer overload resolution to instantiation
    time.  But we have to know now whether to capture this or not.
-   Do that if FNS contains any non-static fns.
-   The std doesn't anticipate this case, but I expect this to be the
-   outcome of discussion.  */
+   Do that if FNS contains any non-static fns as per
+   [expr.prim.lambda.capture]/7.1.  */
 
 void
 maybe_generic_this_capture (tree object, tree fns)
@@ -992,7 +991,7 @@ maybe_generic_this_capture (tree object, tree fns)
        for (lkp_iterator iter (fns); iter; ++iter)
          if (((!id_expr && TREE_CODE (*iter) != USING_DECL)
               || TREE_CODE (*iter) == TEMPLATE_DECL)
-             && DECL_IOBJ_MEMBER_FUNCTION_P (*iter))
+             && DECL_OBJECT_MEMBER_FUNCTION_P (*iter))
            {
              /* Found a non-static member.  Capture this.  */
              lambda_expr_this_capture (lam, /*maybe*/-1);
diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-lambda15.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-lambda15.C
new file mode 100644 (file)
index 0000000..369f089
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/119038
+// { dg-do compile { target c++23 } }
+
+struct A {
+  void f() {
+    [&](auto x) { g(x); h(x); }(0);
+  }
+
+  void g(this A&, int);
+  void h(this auto&, auto);
+};