Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

In r16-970 I changed finish_this_expr to look at current_class_type rather
than current_class_ptr to accommodate explicit object lambdas.  But here in
a lambda in the noexcept-spec, the closure type doesn't yet have the
function as its context, so lambda_expr_this_capture can't find the function
and gives up.  But in this context current_class_ptr refers to the
function's 'this', so let's go back to using it in that case.

        PR c++/121008
        PR c++/113563

gcc/cp/ChangeLog:

        * semantics.cc (finish_this_expr): Do check current_class_ref for
        non-lambda.

gcc/testsuite/ChangeLog:

        * g++.dg/cpp2a/lambda-uneval28.C: New test.
---
 gcc/cp/semantics.cc                          |  8 +++++---
 gcc/testsuite/g++.dg/cpp2a/lambda-uneval28.C | 10 ++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-uneval28.C

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 28baf7b3172..b57547cb8af 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -3605,11 +3605,13 @@ finish_this_expr (void)
 {
   tree result = NULL_TREE;
 
-  if (current_class_type && LAMBDA_TYPE_P (current_class_type))
+  if (current_class_ref && !LAMBDA_TYPE_P (TREE_TYPE (current_class_ref)))
+    result = current_class_ptr;
+  else if (current_class_type && LAMBDA_TYPE_P (current_class_type))
     result = (lambda_expr_this_capture
              (CLASSTYPE_LAMBDA_EXPR (current_class_type), /*add*/true));
-  else if (current_class_ptr)
-    result = current_class_ptr;
+  else
+    gcc_checking_assert (!current_class_ptr);
 
   if (result)
     /* The keyword 'this' is a prvalue expression.  */
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval28.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval28.C
new file mode 100644
index 00000000000..4b1bfc8f026
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval28.C
@@ -0,0 +1,10 @@
+// PR c++/121008
+// { dg-do compile { target c++20 } }
+
+struct A {
+  void f()
+    noexcept(noexcept([this]() noexcept(noexcept(this)) {}))
+  {}
+};
+
+int main() {}

base-commit: 41c446389446a357172883389e36fd10c882ce6d
-- 
2.49.0

Reply via email to