if (cp_unevaluated_operand)
add_capture_p = false;
+ /* If we captured 'this' but don't have a capture proxy yet, look up the
+ captured 'this' again. */
+ if (this_capture && TREE_CODE (this_capture) == FIELD_DECL)
+ {
+ gcc_assert (!add_capture_p);
+ this_capture = NULL_TREE;
+ }
+
/* Try to default capture 'this' if we can. */
if (!this_capture)
{
result = rvalue (result);
}
+ gcc_checking_assert (!result || result == error_mark_node
+ || TYPE_PTR_P (TREE_TYPE (result)));
+
return result;
}
/* Recognize the `this' keyword. */
case RID_THIS:
cp_lexer_consume_token (parser->lexer);
- if (parser->local_variables_forbidden_p & THIS_FORBIDDEN)
+ if ((parser->local_variables_forbidden_p & THIS_FORBIDDEN)
+ /* It's OK to refer to 'this' in an unevaluated operand in a
+ lambda default argument (lambda-targ16.C). */
+ && !cp_unevaluated_operand)
{
error_at (token->location,
"%<this%> may not be used in this context");
void m3 () noexcept(noexcept(this->a)) { }
void m4 () noexcept(noexcept(this)) { }
- static auto m5 () -> decltype(this->a) { return 0; } // { dg-error ".this. may not be used in this context" }
- static auto m6 () -> decltype(this) { return 0; } // { dg-error ".this. may not be used in this context" }
- static void m7 () noexcept(noexcept(this->a)) { } // { dg-error ".this. may not be used in this context" }
- static void m8 () noexcept(noexcept(this)) { } // { dg-error ".this. may not be used in this context" }
+ static auto m5 () -> decltype(this->a) { return 0; } // { dg-error ".this." }
+ static auto m6 () -> decltype(this) { return 0; } // { dg-error ".this." }
+ static void m7 () noexcept(noexcept(this->a)) { } // { dg-error ".this." }
+ static void m8 () noexcept(noexcept(this)) { } // { dg-error ".this." }
};
template <typename T>
}
struct S5 {
- friend auto bar() -> decltype(this); // { dg-error ".this. may not be used in this context" }
+ friend auto bar() -> decltype(this); // { dg-error ".this." }
auto bar2() -> decltype(this);
};
--- /dev/null
+// PR c++/120748
+// From Clang cxx20-lambda-decltype-this.cpp.
+// { dg-do compile { target c++20 } }
+
+namespace PR45881 {
+struct A {
+ void f();
+};
+int id(A*);
+void A::f() {
+ auto z = [*this](auto z2, decltype(z2(this)) z3){};
+ z(id,3);
+}
+
+struct B {
+ void f();
+};
+void B::f() {
+ auto z = []<typename TT, typename TTT=decltype(TT()(this))>(){return 0;};
+ z.template operator()<int(*)(B*)>();
+}
+struct C {
+ void f();
+};
+void C::f() {
+ auto z = []<typename TT, decltype(TT()(this)) n>(){return 0;};
+ z.template operator()<int(*)(C*), 8>();
+}
+} // namespace PR45881