]> granicus.if.org Git - clang/commitdiff
Correct more typos in conditional expressions
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 17 Feb 2016 17:19:00 +0000 (17:19 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 17 Feb 2016 17:19:00 +0000 (17:19 +0000)
We didn't correctly handle some edge cases, causing us to bail out
before correcting all the typos.

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

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

index 8a6bcb3b37bd55366b3d4717d249f6afef0ae2f7..82f36856940adc2147ad8137bda75733d143d78f 100644 (file)
@@ -449,9 +449,11 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
         LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc,
                                          LHS.get(), TernaryMiddle.get(),
                                          RHS.get());
-    } else
-      // Ensure potential typos in the RHS aren't left undiagnosed.
+    } else {
+      // Ensure potential typos aren't left undiagnosed.
+      Actions.CorrectDelayedTyposInExpr(TernaryMiddle);
       Actions.CorrectDelayedTyposInExpr(RHS);
+    }
   }
 }
 
index 44a39d7cad77a7c76ce387e6f1e772b50916a98b..5976c2c9f34508d9369274e113a5f269780c6a69 100644 (file)
@@ -6838,8 +6838,23 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc,
     // doesn't handle dependent types properly, so make sure any TypoExprs have
     // been dealt with before checking the operands.
     ExprResult CondResult = CorrectDelayedTyposInExpr(CondExpr);
-    if (!CondResult.isUsable()) return ExprError();
+    ExprResult LHSResult = CorrectDelayedTyposInExpr(LHSExpr);
+    ExprResult RHSResult = CorrectDelayedTyposInExpr(RHSExpr);
+
+    if (!CondResult.isUsable())
+      return ExprError();
+
+    if (LHSExpr) {
+      if (!LHSResult.isUsable())
+        return ExprError();
+    }
+
+    if (!RHSResult.isUsable())
+      return ExprError();
+
     CondExpr = CondResult.get();
+    LHSExpr = LHSResult.get();
+    RHSExpr = RHSResult.get();
   }
 
   // If this is the gnu "x ?: y" extension, analyze the types as though the LHS
index 4ef50570899c2dfa244f6f55684290702dc27bae..53b3b67ef2b9104501542545a2d141ae78f1b549 100644 (file)
@@ -55,3 +55,5 @@ void fn2() {
   f(THIS_IS_AN_ERROR, // expected-error {{use of undeclared identifier 'THIS_IS_AN_ERROR'}}
     afunction(afunction_));  // expected-error {{use of undeclared identifier 'afunction_'; did you mean 'afunction'?}}
 }
+
+int d = X ? d : L; // expected-error 2 {{use of undeclared identifier}}
index 07c1634431ea1537805610750fdec6d565c8b61f..4f7c4e61fad6d4cefb86801e1c24cff1269a7eac 100644 (file)
@@ -663,3 +663,5 @@ class Bar : public A::B::Foofoo {};
 
 using C::D::Foofoo;  // expected-error {{no member named 'Foofoo' in namespace 'PR24781_using_crash::C::D'; did you mean 'A::B::Foofoo'?}}
 }
+
+int d = ? L : d; // expected-error {{expected expression}} expected-error {{undeclared identifier}}