Tested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 14? -- >8 --
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. gcc/testsuite/ChangeLog: * g++.dg/cpp23/explicit-obj-lambda15.C: New test. --- gcc/cp/lambda.cc | 2 +- gcc/testsuite/g++.dg/cpp23/explicit-obj-lambda15.C | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp23/explicit-obj-lambda15.C diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 09898f6746c..9679fdc1a2d 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -992,7 +992,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 00000000000..369f0895ed1 --- /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); +}; -- 2.49.0.rc0