| Issue |
84163
|
| Summary |
Capture of `*this` in explicit object parameter lambda doesn't respect qualifiers
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
wreien
|
```cpp
struct S {
int x;
auto foo() {
return [*this](this auto&&) {
__builtin_printf("%d ", x);
x = 10;
};
}
};
int main() {
S s{ 5 };
const auto l = s.foo();
l();
s.x = 15;
l();
__builtin_printf("%d\n", s.x);
}
```
https://godbolt.org/z/35qjr473K
Expected: an error that you cannot modify `x` within a `const` lambda.
Result: Prints `5 10 15`, demonstrating both that `l` has captured a copy of `S`, and also that (despite being a `const` object) it is nevertheless mutating its own state.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs