[PATCH] D137172: [Clang] Implement CWG2358 Explicit capture of value

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 2 06:18:28 PDT 2022


aaron.ballman added inline comments.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:162
+    // Init captures are always VarDecl.
+    auto *D = cast<VarDecl>(LC.getCapturedVar());
+    Invalid |= Visit(D->getInit());
----------------
Can you add a test case showing what happens with structured bindings? e.g.,
```
int array[] = { 1, 2 };
auto [a, b] = array; 

void func(int c = [x = a] { return x; }());
```
Note, I think Clang has a bug here so you might have to write the test with a FIXME comment. (I don't think we implement https://wg21.link/cwg2358 or http://eel.is/c++draft/expr.prim.lambda#capture-3 properly yet.)

The part that worries me there specifically is that a `BindingDecl` is a `ValueDecl` and not a `VarDecl`, so I think that `cast<>` may assert in this case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137172/new/

https://reviews.llvm.org/D137172



More information about the cfe-commits mailing list