[clang] [Clang] Prevent assignment to captured structured bindings inside immutable lambda (PR #120849)

via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 23 08:49:46 PST 2024


================
@@ -13299,7 +13293,18 @@ static NonConstCaptureKind isReferenceToNonConstCapture(Sema &S, Expr *E) {
 
   // The declaration must be a variable which is not declared 'const'.
   VarDecl *var = dyn_cast<VarDecl>(DRE->getDecl());
-  if (!var) return NCCK_None;
+  if (!var) {
+    // Bindings also can be captured by lambda in C++
+    BindingDecl *binding = dyn_cast<BindingDecl>(DRE->getDecl());
----------------
cor3ntin wrote:

```suggestion
    BindingDecl *Binding = dyn_cast<BindingDecl>(DRE->getDecl());
```

https://github.com/llvm/llvm-project/pull/120849


More information about the cfe-commits mailing list