-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Permitted assignment to read-only capture in not-mutable lambda #95081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-frontend Author: Fedor Chelnokov (Fedr)
This program
```
struct B {
int i;
};
int foo() {
|
If we use Which is llvm-project/clang/lib/Sema/SemaExpr.cpp Line 13507 in a13bc97
It looks like when running llvm-project/clang/lib/AST/ExprClassification.cpp Lines 677 to 680 in a13bc97
In the OP's case |
We're computing the wrong type for the void f(int&) = delete;
void f(const int&);
int arr[1];
void foo() {
auto [x] = arr;
[x]() { f(x); }();
} |
At this point: llvm-project/clang/lib/Sema/SemaExpr.cpp Line 3332 in 7cff05a
for the So it looks like we skip the When we do the lookup here: llvm-project/clang/lib/Sema/SemaDecl.cpp Lines 1281 to 1283 in 8b18684
We are missing the capture in the OP's case. |
… inside immutable lambda (#120849) For structured bindings, a call to getCapturedDeclRefType(...) was missing. This PR fixes that behavior and adds the related diagnostics too. This fixes llvm/llvm-project#95081.
This program
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/46o6jad8nThe text was updated successfully, but these errors were encountered: