Closed
Description
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{};
}();
}