[PATCH] D78365: [AST] Preserve the invalid initializer for auto VarDecl.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 07:32:19 PDT 2020


sammccall added a comment.

Nice!

Yet another case of "do we need to stop here" though. Do you have a doc or bug or somewhere to collect the different directions we could/should extend in?



================
Comment at: clang/lib/Sema/SemaDecl.cpp:11852
+      // There are unresolved typos in Init. Usually it indicates the
+      // initializer is very ill-formed, just drop it.
       RealDecl->setInvalidDecl();
----------------
Do you have an example to back this up? (Not to include in the comment, just curious).

ISTM when there are errors in the input, you can get "lucky" and they turn into recoveryexpr and survive here, or you get "unlucky" and they turn into typoexpr and are dropped here after correction fails. And lucky/unlucky might mostly depend on details about the type of error, not how ill-formed the code is?

This suggests two possible recovery strategies:
 - if CorrectDelayedTyposInExpr fails typo-correction, it could rebuild with the typos "degraded" to RecoveryExpr of some sort
 - or we could just wrap `Init` in `RecoveryExpr`, TypoExprs and all. With the assumption that stuff that doesn't handle TypoExpr should either treate RecoveryExpr as opaque or should bail out at the top-level based on ContainsErrors.

The former seems more precise and more general, probably more work too.

None of this needs to be addressed in this patch except maybe a FIXME and/or a tweak to the existing comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78365/new/

https://reviews.llvm.org/D78365





More information about the cfe-commits mailing list