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

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 16 09:43:13 PST 2023


================
@@ -13540,6 +13540,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 concrete type (e.g.
+      //    `int [a, b] = 1;`), and the initializer is invalid;
+      // Case 1) is already handled earlier in this function.
+      if (llvm::isa<DecompositionDecl>(VDecl)) // Case 2)
+        VDecl->setInvalidDecl();
----------------
cor3ntin wrote:

Maybe we should move the `1)` part of the comment line 13496, or just remove it entirely. 

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


More information about the cfe-commits mailing list