type = lambda_proxy_type (object);
- if (name == this_identifier && !INDIRECT_TYPE_P (type))
+ if (name == this_identifier && !INDIRECT_TYPE_P (TREE_TYPE (member)))
{
type = build_pointer_type (type);
type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
else
{
/* To make sure that current_class_ref is for the lambda. */
- gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref))
- == LAMBDA_EXPR_CLOSURE (lambda));
+ gcc_assert (!current_class_ref
+ || (TYPE_MAIN_VARIANT (TREE_TYPE (current_class_ref))
+ == LAMBDA_EXPR_CLOSURE (lambda)));
result = this_capture;
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)
{
else if (PACK_EXPANSION_P (type))
/* Don't bother trying to represent this. */
type = NULL_TREE;
- else if (WILDCARD_TYPE_P (TREE_TYPE (object)))
+ else if (!TREE_TYPE (object) || WILDCARD_TYPE_P (TREE_TYPE (object)))
/* We don't know what the eventual quals will be, so punt until
instantiation time.
{
tree result = NULL_TREE;
- if (current_class_ptr)
- {
- tree type = TREE_TYPE (current_class_ref);
-
- /* In a lambda expression, 'this' refers to the captured 'this'. */
- if (LAMBDA_TYPE_P (type))
- result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type), true);
- else
- result = current_class_ptr;
- }
+ 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;
if (result)
/* The keyword 'this' is a prvalue expression. */
--- /dev/null
+// PR c++/113563
+// { dg-do compile { target c++23 } }
+
+struct S {
+ int x_;
+ void f() {
+ [this](this auto) {
+ this->x_ = 42;
+ return this;
+ }();
+ }
+};
+
+struct R {
+ int x;
+
+ auto foo() {
+ return [*this](this auto &self) {
+ this->x = 4;
+ };
+ }
+};
+
+
+struct A
+{
+ int n;
+ void fun()
+ {
+ auto _ = [&](this auto self) { return n; };
+ }
+};
+
+struct B {
+ int i = 42;
+ int foo() {
+ return [this](this auto &&self) { auto p = &i; return *p; }();
+ }
+};