From de18bd8785694c9f0f5ba9806c0381ab97101661 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 17 Feb 2016 17:19:00 +0000 Subject: [PATCH] Correct more typos in conditional expressions 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 | 6 ++++-- lib/Sema/SemaExpr.cpp | 17 ++++++++++++++++- test/Sema/typo-correction.c | 2 ++ test/SemaCXX/typo-correction.cpp | 2 ++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 8a6bcb3b37..82f3685694 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -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); + } } } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 44a39d7cad..5976c2c9f3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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 diff --git a/test/Sema/typo-correction.c b/test/Sema/typo-correction.c index 4ef5057089..53b3b67ef2 100644 --- a/test/Sema/typo-correction.c +++ b/test/Sema/typo-correction.c @@ -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}} diff --git a/test/SemaCXX/typo-correction.cpp b/test/SemaCXX/typo-correction.cpp index 07c1634431..4f7c4e61fa 100644 --- a/test/SemaCXX/typo-correction.cpp +++ b/test/SemaCXX/typo-correction.cpp @@ -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}} -- 2.40.0