[Clang][C++20] Support capturing structured bindings in lambdas
authorCorentin Jabot <corentinjabot@gmail.com>
Wed, 30 Mar 2022 12:27:44 +0000 (14:27 +0200)
committerCorentin Jabot <corentinjabot@gmail.com>
Wed, 3 Aug 2022 18:00:01 +0000 (20:00 +0200)
commit44f2baa3804a62ca793f0ff3e43aa71cea91a795
tree1a785e70b9c89761ed4af517d18f49c7ed709c96
parent3aef968ec3faada22319aaa3530776974082d2d5
[Clang][C++20] Support capturing structured bindings in lambdas

This completes the implementation of P1091R3 and P1381R1.

This patch allow the capture of structured bindings
both for C++20+ and C++17, with extension/compat warning.

In addition, capturing an anonymous union member,
a bitfield, or a structured binding thereof now has a
better diagnostic.

We only support structured bindings - as opposed to other kinds
of structured statements/blocks. We still emit an error for those.

In addition, support for structured bindings capture is entirely disabled in
OpenMP mode as this needs more investigation - a specific diagnostic indicate the feature is not yet supported there.

Note that the rest of P1091R3 (static/thread_local structured bindings) was already implemented.

at the request of @shafik, i can confirm the correct behavior of lldb wit this change.

Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/52720

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122768
41 files changed:
clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/LambdaCapture.h
clang/include/clang/AST/Stmt.h
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/Analysis/AnalysisDeclContext.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
clang/test/CodeGenCXX/cxx20-decomposition.cpp [new file with mode: 0644]
clang/test/SemaCXX/cxx1z-decomposition.cpp
clang/test/SemaCXX/cxx20-decomposition.cpp [new file with mode: 0644]
clang/test/SemaCXX/decomposition-blocks.cpp [new file with mode: 0644]
clang/test/SemaCXX/decomposition-openmp.cpp [new file with mode: 0644]
clang/tools/libclang/CIndex.cpp
clang/www/cxx_status.html