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.
{
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. */
--- /dev/null
+// PR c++/121008
+// { dg-do compile { target c++20 } }
+
+struct A {
+ void f()
+ noexcept(noexcept([this]() noexcept(noexcept(this)) {}))
+ {}
+};
+
+int main() {}