-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Closed
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerlambdaC++11 lambda expressionsC++11 lambda expressions
Description
When trying to create a mutable lambda with const object captured by reference and then mutate that object
int main() {
const int a = 69;
auto lambda = [&r = a](int x) mutable {
r += x;
return r;
};
}you got incorrect error message
<source>:4:11: error: cannot assign to a variable captured by copy in a non-mutable lambda
4 | r += x;
| ~ ^
but r is captured by reference and lambda is mutable
godbolt example: https://godbolt.org/z/sKd3bh6aM
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerlambdaC++11 lambda expressionsC++11 lambda expressions