[PATCH] D81090: [AST][RecoveryExpr] Preserve the AST for invalid class constructions.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 12 08:03:27 PDT 2020


hokein updated this revision to Diff 270402.
hokein added a comment.

rebase to master and adjust the diagnostic tests after "-frecovery-ast" is flipped on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81090

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/cxx0x-initializer-constructor.cpp
  clang/test/SemaCXX/cxx1z-copy-omission.cpp


Index: clang/test/SemaCXX/cxx1z-copy-omission.cpp
===================================================================
--- clang/test/SemaCXX/cxx1z-copy-omission.cpp
+++ clang/test/SemaCXX/cxx1z-copy-omission.cpp
@@ -106,7 +106,7 @@
   sizeof(Indestructible{}); // expected-error {{deleted}}
   sizeof(make_indestructible()); // expected-error {{deleted}}
   sizeof(make_incomplete()); // expected-error {{incomplete}}
-  typeid(Indestructible{}); // expected-error {{deleted}}
+  typeid(Indestructible{}); // expected-error {{deleted}} expected-error {{you need to include <typeinfo>}}
   typeid(make_indestructible()); // expected-error {{deleted}} \
                                  // expected-error {{need to include <typeinfo>}}
   typeid(make_incomplete()); // expected-error {{incomplete}} \
Index: clang/test/SemaCXX/cxx0x-initializer-constructor.cpp
===================================================================
--- clang/test/SemaCXX/cxx0x-initializer-constructor.cpp
+++ clang/test/SemaCXX/cxx0x-initializer-constructor.cpp
@@ -163,7 +163,7 @@
     // (for the second phase, no constructor is viable)
     G g1{1, 2, 3}; // expected-error {{no matching constructor}}
     (void) new G{1, 2, 3}; // expected-error {{no matching constructor}}
-    (void) G{1, 2, 3} // expected-error {{no matching constructor}}
+    (void) G{1, 2, 3}; // expected-error {{no matching constructor}}
 
     // valid (T deduced to <>).
     G g2({1, 2, 3});
Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2043,14 +2043,11 @@
         X<A().k>::n; // expected-note {{in evaluation of exception specification for 'BadDefaultInit::A::A' needed here}}
   };
 
-  // FIXME: The "constexpr constructor must initialize all members" diagnostic
-  // here is bogus (we discard the k(k) initializer because the parameter 'k'
-  // has been marked invalid).
   struct B {
-    constexpr B( // expected-warning {{initialize all members}}
+    constexpr B(
         int k = X<B().k>::n) : // expected-error {{default argument to function 'B' that is declared later}} expected-note {{here}}
       k(k) {}
-    int k; // expected-note {{not initialized}}
+    int k;
   };
 }
 
Index: clang/test/AST/ast-dump-recovery.cpp
===================================================================
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -159,11 +159,18 @@
   // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors
   // CHECK-NEXT:  `-InitListExpr
   Bar b2 = {1};
-  // FIXME: preserve the invalid initializer.
-  // CHECK: `-VarDecl {{.*}} b3 'Bar'
+  // CHECK:     `-VarDecl {{.*}} b3 'Bar'
+  // CHECK-NEXT:  `-CXXConstructExpr {{.*}} <col:12, col:17> 'Bar' contains-errors
+  // CHECK-NEXT:    `-ImplicitCastExpr {{.*}} <col:12, col:17> 'const Bar' contains-errors
+  // CHECK-NEXT:      `-RecoveryExpr {{.*}} 'Bar' contains-errors lvalue
+  // CHECK-NEXT:        `-DeclRefExpr {{.*}} 'x' 'int'
   Bar b3 = Bar(x);
-  // FIXME: preserve the invalid initializer.
-  // CHECK: `-VarDecl {{.*}} b4 'Bar'
+  // CHECK:     `-VarDecl {{.*}} b4 'Bar'
+  // CHECK-NEXT:  `-CXXConstructExpr {{.*}} <col:12, col:17> 'Bar' contains-errors
+  // CHECK-NEXT:    `-ImplicitCastExpr {{.*}} 'const Bar' contains-errors
+  // CHECK-NEXT:      `-RecoveryExpr {{.*}} 'Bar' contains-errors
+  // CHECK-NEXT:        `-InitListExpr {{.*}} 'void'
+  // CHECK-NEXT:          `-DeclRefExpr {{.*}} 'x' 'int'
   Bar b4 = Bar{x};
   // CHECK:     `-VarDecl {{.*}} b5 'Bar'
   // CHECK-NEXT: `-CXXUnresolvedConstructExpr {{.*}} 'Bar' contains-errors 'Bar'
@@ -176,6 +183,10 @@
   // CHECK-NEXT:   `-RecoveryExpr {{.*}} contains-errors
   // CHECK-NEXT:     `-UnresolvedLookupExpr {{.*}} 'invalid'
   Bar b6 = Bar{invalid()};
+
+  // CHECK:     `-RecoveryExpr {{.*}} 'Bar' contains-errors
+  // CHECK-NEXT:  `-IntegerLiteral {{.*}} 'int' 1
+  Bar(1);
 }
 void InitializerForAuto() {
   // CHECK:     `-VarDecl {{.*}} invalid a 'auto'
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1389,6 +1389,9 @@
   if (!Result.isInvalid() && Result.get()->isInstantiationDependent() &&
       !Result.get()->isTypeDependent())
     Result = CorrectDelayedTyposInExpr(Result.get());
+  else if (Result.isInvalid())
+    Result = CreateRecoveryExpr(TInfo->getTypeLoc().getBeginLoc(),
+                                RParenOrBraceLoc, exprs, Ty);
   return Result;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81090.270402.patch
Type: text/x-patch
Size: 4669 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200612/3f620b80/attachment-0001.bin>


More information about the cfe-commits mailing list