[clang] 7af852d - [AST][RecoveryExpr] Preserve the invalid "undef_var" initializer.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 21 00:38:23 PDT 2020
Author: Haojian Wu
Date: 2020-07-21T09:38:09+02:00
New Revision: 7af852dcbff9a4d5034e6deaadb7b630c548c6fa
URL: https://github.com/llvm/llvm-project/commit/7af852dcbff9a4d5034e6deaadb7b630c548c6fa
DIFF: https://github.com/llvm/llvm-project/commit/7af852dcbff9a4d5034e6deaadb7b630c548c6fa.diff
LOG: [AST][RecoveryExpr] Preserve the invalid "undef_var" initializer.
And don't invalidate the VarDecl if the type is known.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D81395
Added:
Modified:
clang/lib/Sema/SemaDecl.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/SemaCXX/typo-correction-delayed.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3413a420430c..406c9c712564 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12039,7 +12039,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
// Try to correct any TypoExprs in the initialization arguments.
for (size_t Idx = 0; Idx < Args.size(); ++Idx) {
ExprResult Res = CorrectDelayedTyposInExpr(
- Args[Idx], VDecl, /*RecoverUncorrectedTypos=*/false,
+ Args[Idx], VDecl, /*RecoverUncorrectedTypos=*/true,
[this, Entity, Kind](Expr *E) {
InitializationSequence Init(*this, Entity, Kind, MultiExprArg(E));
return Init.Failed() ? ExprError() : E;
diff --git a/clang/test/AST/ast-dump-recovery.cpp b/clang/test/AST/ast-dump-recovery.cpp
index 4d11bb29d5bf..fd7c923b7e51 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -24,8 +24,11 @@ void test_invalid_call(int s) {
// CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} 'some_func'
// CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors
s = some_func(undef1);
- // CHECK: `-VarDecl {{.*}} invalid var 'int'
- // FIXME: preserve the broken call.
+
+ // CHECK: VarDecl {{.*}} var 'int'
+ // CHECK-NEXT: `-CallExpr {{.*}} '<dependent type>' contains-errors
+ // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} 'some_func'
+ // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors
int var = some_func(undef1);
}
@@ -178,9 +181,15 @@ void InvalidInitalizer(int x) {
// CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} 'invalid'
Bar b6 = Bar{invalid()};
- // CHECK: `-RecoveryExpr {{.*}} 'Bar' contains-errors
+ // CHECK: RecoveryExpr {{.*}} 'Bar' contains-errors
// CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
Bar(1);
+
+ // CHECK: `-VarDecl {{.*}} var1
+ // CHECK-NEXT: `-BinaryOperator {{.*}} '<dependent type>' contains-errors
+ // CHECK-NEXT: |-RecoveryExpr {{.*}} '<dependent type>' contains-errors
+ // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+ int var1 = undef + 1;
}
void InitializerForAuto() {
// CHECK: `-VarDecl {{.*}} invalid a 'auto'
diff --git a/clang/test/SemaCXX/typo-correction-delayed.cpp b/clang/test/SemaCXX/typo-correction-delayed.cpp
index 610d43971381..66d19daf66fd 100644
--- a/clang/test/SemaCXX/typo-correction-delayed.cpp
+++ b/clang/test/SemaCXX/typo-correction-delayed.cpp
@@ -149,7 +149,8 @@ void test() {
}
namespace PR21905 {
-int (*a) () = (void)Z; // expected-error-re {{use of undeclared identifier 'Z'{{$}}}}
+int (*a)() = (void)Z; // expected-error-re {{use of undeclared identifier 'Z'{{$}}}} \
+ // expected-error {{cannot initialize a variable of type 'int (*)()' with an rvalue of type 'void'}}
}
namespace PR21947 {
More information about the cfe-commits
mailing list