Permitted assignment to read-only capture in not-mutable lambda #95081
Closed
Description
This program
struct B {
int i;
};
int foo() {
auto [x] = B{1};
[x]() {
x = 2;
}();
return x;
}
is invalid because not-mutable lambda modifies its read-only capture x
, and it is properly rejected by GCC and MSVC, but Clang erroneously admits it. Online demo: https://gcc.godbolt.org/z/46o6jad8n
Metadata
Assignees
Labels
Type
Projects
Status
Done