diff options
author | Patrick Palka <ppalka@redhat.com> | 2025-02-28 10:56:49 -0500 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2025-02-28 10:56:49 -0500 |
commit | 1a150f1f688486b12cd975bdc4cd1bd52a7e0110 (patch) | |
tree | e15d974b8f7b2cc62ad1a1bc8b919a7e49af0f24 /gcc | |
parent | 815f1f27a1dba2f0acd1f02d0beafedadebe967c (diff) | |
download | gcc-1a150f1f688486b12cd975bdc4cd1bd52a7e0110.zip gcc-1a150f1f688486b12cd975bdc4cd1bd52a7e0110.tar.gz gcc-1a150f1f688486b12cd975bdc4cd1bd52a7e0110.tar.bz2 |
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 <jason@redhat.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/lambda.cc | 7 | ||||
-rw-r--r-- | 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 09898f6..da075b9 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -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 index 0000000..369f089 --- /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); +}; |