[clang] [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. (PR #72428)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 16 12:15:32 PST 2024


================
@@ -13570,6 +13570,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
           CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), Args);
       if (RecoveryExpr.get())
         VDecl->setInit(RecoveryExpr.get());
+      // In general, for error recovery purposes, the initalizer doesn't play
+      // part in the valid bit of the declaration. There are a few exceptions:
+      //  1) if the var decl has a deduced auto type, and the type cannot be
+      //     deduced by an invalid initializer;
+      //  2) if the var decl is decompsition decl with a non-deduced type, and
+      //     the initialization fails (e.g. `int [a] = {1, 2};`);
+      // Case 1) was already handled elsewhere.
+      if (llvm::isa<DecompositionDecl>(VDecl)) // Case 2)
----------------
AaronBallman wrote:

```suggestion
      if (isa<DecompositionDecl>(VDecl)) // Case 2)
```

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


More information about the cfe-commits mailing list