]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: lambda this capture and requires [PR120123]
authorJason Merrill <jason@redhat.com>
Fri, 30 May 2025 22:27:45 +0000 (18:27 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 2 Jun 2025 15:40:51 +0000 (11:40 -0400)
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.

gcc/cp/lambda.cc
gcc/testsuite/g++.dg/cpp2a/concepts-lambda24.C [new file with mode: 0644]

index 5bbdddfb0b9b8030ab758b8f4035aec6e6400a82..c380edd774864af363333cbd126fa1c88882979b 100644 (file)
@@ -975,12 +975,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 (file)
index 0000000..28f56ca
--- /dev/null
@@ -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);
+        };
+    }
+};