r261312 - Correct typos after acting on invalid subscript expressions

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 18 23:15:34 PST 2016


Author: majnemer
Date: Fri Feb 19 01:15:33 2016
New Revision: 261312

URL: http://llvm.org/viewvc/llvm-project?rev=261312&view=rev
Log:
Correct typos after acting on invalid subscript expressions

Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/test/SemaCXX/typo-correction.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=261312&r1=261311&r2=261312&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri Feb 19 01:15:33 2016
@@ -1434,8 +1434,10 @@ Parser::ParsePostfixExpressionSuffix(Exp
 
       // 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(Exp
 
       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(Exp
                                                 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();

Modified: cfe/trunk/test/SemaCXX/typo-correction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction.cpp?rev=261312&r1=261311&r2=261312&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typo-correction.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction.cpp Fri Feb 19 01:15:33 2016
@@ -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}}
+};
+}




More information about the cfe-commits mailing list