]> granicus.if.org Git - clang/commitdiff
[Parser] Fix bug where delayed typo in conditional expression was corrected twice
authorErik Pilkington <erik.pilkington@gmail.com>
Fri, 29 Jul 2016 00:55:40 +0000 (00:55 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Fri, 29 Jul 2016 00:55:40 +0000 (00:55 +0000)
Patch by David Tarditi!

Differential revision: https://reviews.llvm.org/D22930

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277095 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
test/Sema/typo-correction.c

index c71e270cb4c4d5b55dd85281c3f381a2f897bc70..3788b18f07308c9c24212470e435740cfd5090db 100644 (file)
@@ -446,14 +446,15 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
         LHS = Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(),
                                  OpToken.getKind(), LHS.get(), RHS.get());
 
-        // In this case, ActOnBinOp performed the CorrectDelayedTyposInExpr check.
-        if (!getLangOpts().CPlusPlus)
-          continue;
       } else {
         LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc,
                                          LHS.get(), TernaryMiddle.get(),
                                          RHS.get());
       }
+      // In this case, ActOnBinOp or ActOnConditionalOp performed the
+      // CorrectDelayedTyposInExpr check.
+      if (!getLangOpts().CPlusPlus)
+        continue;
     }
     // Ensure potential typos aren't left undiagnosed.
     if (LHS.isInvalid()) {
index a1107a25ee54b3d52316072eb2e74a834778d31c..59f022dfe528cf9e1796a0b3d547a0564e59aa7c 100644 (file)
@@ -65,3 +65,18 @@ int fn_with_rs(int r) { r = TYPO + r * TYPO; } // expected-error 2 {{use of unde
 void fn_with_unknown(int a, int b) {
   fn_with_unknown(unknown, unknown | unknown); // expected-error 3 {{use of undeclared identifier}}
 }
+
+// Two typos in a parenthesized expression or argument list with a conditional
+// expression caused a crash in C mode.
+//
+// r272587 fixed a similar bug for binary operations. The same fix was needed for
+// conditional expressions.
+
+int g(int x, int y) {
+  return x + y;
+}
+
+int h() {
+  g(x, 5 ? z : 0); // expected-error 2 {{use of undeclared identifier}}
+  (x, 5 ? z : 0);  // expected-error 2 {{use of undeclared identifier}}
+}