]> granicus.if.org Git - clang/commitdiff
Correct typos after acting on invalid subscript expressions
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 19 Feb 2016 07:15:33 +0000 (07:15 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 19 Feb 2016 07:15:33 +0000 (07:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261312 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
test/SemaCXX/typo-correction.cpp

index 32262f433d15e4ebf6c50f4349829c3ec3b195c3..07f750550eae6b4d898c5cb88b1fbf66e4a9f6e9 100644 (file)
@@ -1434,8 +1434,10 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
 
       // Reject array indices starting with a lambda-expression. '[[' is
       // reserved for attributes.
-      if (CheckProhibitedCXX11Attribute())
+      if (CheckProhibitedCXX11Attribute()) {
+        (void)Actions.CorrectDelayedTyposInExpr(LHS);
         return ExprError();
+      }
 
       BalancedDelimiterTracker T(*this, tok::l_square);
       T.consumeOpen();
@@ -1463,6 +1465,7 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
 
       SourceLocation RLoc = Tok.getLocation();
 
+      ExprResult OrigLHS = LHS;
       if (!LHS.isInvalid() && !Idx.isInvalid() && !Length.isInvalid() &&
           Tok.is(tok::r_square)) {
         if (ColonLoc.isValid()) {
@@ -1473,7 +1476,10 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
                                                 Idx.get(), RLoc);
         }
       } else {
-        (void)Actions.CorrectDelayedTyposInExpr(LHS);
+        LHS = ExprError();
+      }
+      if (LHS.isInvalid()) {
+        (void)Actions.CorrectDelayedTyposInExpr(OrigLHS);
         (void)Actions.CorrectDelayedTyposInExpr(Idx);
         (void)Actions.CorrectDelayedTyposInExpr(Length);
         LHS = ExprError();
index ae6bfa53c93ab573b7acba547f1f777e0e53cbb9..48597ded1528a7a4d59dea987efc05078779e3a6 100644 (file)
@@ -670,3 +670,12 @@ struct B0 {
   int : 0 |         // expected-error {{invalid operands to binary expression}}
       (struct B0)e; // expected-error {{use of undeclared identifier}}
 };
+
+namespace {
+struct a0is0 {};
+struct b0is0 {};
+int g() {
+  0 [                 // expected-error {{subscripted value is not an array}}
+      sizeof(c0is0)]; // expected-error {{use of undeclared identifier}}
+};
+}