aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2025-05-30 18:27:45 -0400
committerJason Merrill <jason@redhat.com>2025-06-02 11:54:04 -0400
commitc096341a0809b322ece478f67c5d7be6923a0169 (patch)
tree62512125f5d69bc53fcd33023f4ba209846d6ca8 /gcc
parentfff23f42e89ecee6c86cd08d809437ee90664b5c (diff)
downloadgcc-c096341a0809b322ece478f67c5d7be6923a0169.zip
gcc-c096341a0809b322ece478f67c5d7be6923a0169.tar.gz
gcc-c096341a0809b322ece478f67c5d7be6923a0169.tar.bz2
c++: lambda this capture and requires [PR120123]
We shouldn't need to be within the lambda body to look through it to the enclosing non-static member function. This change is a small subset of r16-970. PR c++/120123 gcc/cp/ChangeLog: * lambda.cc (nonlambda_method_basetype): Look through lambdas even when current_class_ref is null. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-lambda24.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/lambda.cc5
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/concepts-lambda24.C13
2 files changed, 14 insertions, 4 deletions
diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index b2e0ecd..352e1b9 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -1033,12 +1033,9 @@ current_nonlambda_function (void)
tree
nonlambda_method_basetype (void)
{
- if (!current_class_ref)
- return NULL_TREE;
-
tree type = current_class_type;
if (!type || !LAMBDA_TYPE_P (type))
- return type;
+ return current_class_ref ? type : NULL_TREE;
while (true)
{
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda24.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda24.C
new file mode 100644
index 0000000..28f56ca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda24.C
@@ -0,0 +1,13 @@
+// PR c++/120123
+// { dg-do compile { target c++20 } }
+
+struct H {
+ void member(int) {}
+ void call() {
+ [this]() {
+ [this](const auto& v)
+ requires requires { /*this->*/member(v); }
+ { return member(v); }(0);
+ };
+ }
+};