[clang] [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. (PR #72428)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 16 13:21:56 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();
----------------
shafik wrote:
We should have the comment in both places. This is very helpful to understanding the code.
I agree that having the comment far away from the code that it is commenting on is less useful. The code could easily be moved in a refactor or in other ways and become completely disconnected.
https://github.com/llvm/llvm-project/pull/72428
More information about the cfe-commits
mailing list