From: Ted Kremenek Date: Mon, 12 Apr 2010 22:10:35 +0000 (+0000) Subject: Add fixit hint for missing ':' in ternary expressions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=987aa87cf47811c44ac93afd1913c33f2829ed92;p=clang Add fixit hint for missing ':' in ternary expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101073 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index e479c36792..ee714e8e24 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -336,7 +336,8 @@ Parser::ParseRHSOfBinaryExpression(OwningExprResult LHS, unsigned MinPrec) { } if (Tok.isNot(tok::colon)) { - Diag(Tok, diag::err_expected_colon); + Diag(Tok, diag::err_expected_colon) + << FixItHint::CreateInsertion(Tok.getLocation(), ": "); Diag(OpToken, diag::note_matching) << "?"; return ExprError(); } diff --git a/test/FixIt/fixit.c b/test/FixIt/fixit.c index 7ee5575cf2..4c506df016 100644 --- a/test/FixIt/fixit.c +++ b/test/FixIt/fixit.c @@ -31,3 +31,8 @@ void f1(x, y) int i0 = { 17 }; +int test_cond(int y) { +// CHECK: int x = y ? 1 : 2; + int x = y ? 1 2; + return x; +}