Consider the following piece of code:
void f() {
int a = 3;
[=]() {
[=] () mutable {
a = 5;
}();
}();
}
It compiles on Clang (https://godbolt.org/z/IEXotM) but not on GCC (https://godbolt.org/z/xWXFe6). Error for GCC:
<source>: In lambda function:
<source>:5:15: error: assignment of read-only variable 'a'
5 | a = 5;
| ~~^~~
Compiler returned: 1
According to https://en.cppreference.com/w/cpp/language/lambda,
Optional sequence of specifiers.The following specifiers are allowed:
mutable: allows body to modify the parameters captured by copy, and to call their non-const member functions
And it seems like that Clang's behavior here is correct. Is this the case?