================
@@ -13840,8 +13839,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr
*Init, bool DirectInit) {
return;
}
- if (DeduceVariableDeclarationType(VDecl, DirectInit, Init))
+ if (DeduceVariableDeclarationType(VDecl, DirectInit, Init)) {
+ assert(VDecl->isInvalidDecl() &&
+ "decl should be invalidated when deduce fails");
+ if (auto *RecoveryExpr =
+ CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(),
{Init})
+ .get())
+ VDecl->setInit(RecoveryExpr);
----------------
hokein wrote:
> I wonder if we should move these to the place where the deduction first
> failed. That way we will not have to ensure the error recovery for every
> callers. WDYT?
`DeduceVariableDeclarationType` is only used twice in the codebase, and the
other instance (uninitializedDecl) isn't relevant here.
Within `DeduceVariableDeclarationType`, there are several different failure
cases where the deduction can fail. Moving the code there would probably mean
duplicating the recovery logic multiple times rather than just once here.
Keeping it in the caller is cleaner and avoids that duplication.
https://github.com/llvm/llvm-project/pull/173546
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits