[Sema] Preserve invalid CXXCtorInitializers using RecoveryExpr in initializer
authorSam McCall <sam.mccall@gmail.com>
Fri, 30 Apr 2021 15:21:02 +0000 (17:21 +0200)
committerSam McCall <sam.mccall@gmail.com>
Tue, 10 Aug 2021 13:16:52 +0000 (15:16 +0200)
commit13a86c2bb465edf315ecbccccac622d73d39abe7
tree32b67476a93d46d27abeb44d0a4955560cab2233
parentbd63977ca96acc7db2a546f56a5c0ed1fc93e22a
[Sema] Preserve invalid CXXCtorInitializers using RecoveryExpr in initializer

Before this patch, CXXCtorInitializers that don't typecheck get discarded in
most cases. In particular:

 - typos that can't be corrected don't turn into RecoveryExpr. The full expr
   disappears instead, and without an init expr we discard the node.
 - initializers that fail initialization (e.g. constructor overload resolution)
   are discarded too.

This patch addresses both these issues (a bit clunkily and repetitively, for
member/base/delegating initializers)

It does not preserve any AST nodes when the member/base can't be resolved or
other problems of that nature. That breaks invariants of CXXCtorInitializer
itself, and we don't have a "weak" RecoveryCtorInitializer like we do for Expr.

I believe the changes to diagnostics in existing tests are improvements.
(We're able to do some analysis on the non-broken parts of the initializer)

Differential Revision: https://reviews.llvm.org/D101641
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp