diff options
| -rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 17 | ||||
| -rw-r--r-- | clang/test/Sema/typo-correction.c | 2 | ||||
| -rw-r--r-- | clang/test/SemaCXX/typo-correction.cpp | 2 |
4 files changed, 24 insertions, 3 deletions
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 8a6bcb3b37b..82f36856940 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/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/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 44a39d7cad7..5976c2c9f34 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/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/clang/test/Sema/typo-correction.c b/clang/test/Sema/typo-correction.c index 4ef50570899..53b3b67ef2b 100644 --- a/clang/test/Sema/typo-correction.c +++ b/clang/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/clang/test/SemaCXX/typo-correction.cpp b/clang/test/SemaCXX/typo-correction.cpp index 07c1634431e..4f7c4e61fad 100644 --- a/clang/test/SemaCXX/typo-correction.cpp +++ b/clang/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}} |

