Skip to content

[Clang] Deducing this Lambda ignores assignment rules for captured references #86398

Closed
@Link1J

Description

@Link1J

When using C++23 deducing this, captured references are assignable to anything.
The following code compiles with clang -std=c++23, when it clearly shouldn't. Godbolt

struct function {};
int main() {
    function list;
    [&list](this auto self) {
        list = self;
    }();
}

It even works with types that are not assignable. Godbolt

struct function {
    function& operator=(function const&) = delete;
};
int main() {
    function list;
    [&list](this auto self) {
        list = self;
    }();
}

And even it doesn't even need self as part of the assignment expression. Godbolt

struct function {
    function& operator=(function const&) = delete;
};
int main() {
    function list;
    [&list](this auto self) {
        list = function{};
    }();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepts-invalidc++23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"lambdaC++11 lambda expressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions