https://gcc.gnu.org/g:2ed37595a3c5cf246e8eeea337cf3071c4bb3a59
commit r14-11382-g2ed37595a3c5cf246e8eeea337cf3071c4bb3a59 Author: Patrick Palka <ppa...@redhat.com> Date: Fri Feb 28 10:56:49 2025 -0500 c++: generic lambda, implicit 'this' capture, xobj memfn [PR119038] 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 <ja...@redhat.com> (cherry picked from commit 1a150f1f688486b12cd975bdc4cd1bd52a7e0110) Diff: --- gcc/cp/lambda.cc | 7 +++---- gcc/testsuite/g++.dg/cpp23/explicit-obj-lambda15.C | 11 +++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 5b5e31c141e3..3f69b1fb1264 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -950,9 +950,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) @@ -971,7 +970,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 index 000000000000..369f0895ed10 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-lambda15.C @@ -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); +};