]> granicus.if.org Git - clang/commitdiff
Allow the fixit for missing ':' in the ?: ternary operator if it is pointing
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 24 Jun 2011 17:28:29 +0000 (17:28 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 24 Jun 2011 17:28:29 +0000 (17:28 +0000)
at the start of a macro instantiation.

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

lib/Parse/ParseExpr.cpp
test/FixIt/fixit.c

index 154d8fd80923548d40b1e107559fd500c94ec7e2..218e18f3ad797fd5a5aed9397ed55c9c50687c64 100644 (file)
@@ -309,8 +309,9 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
         // suggest inserting the colon in between them, otherwise insert ": ".
         SourceLocation FILoc = Tok.getLocation();
         const char *FIText = ": ";
-        if (FILoc.isFileID()) {
-          const SourceManager &SM = PP.getSourceManager();
+        const SourceManager &SM = PP.getSourceManager();
+        if (FILoc.isFileID() || SM.isAtStartOfMacroInstantiation(FILoc)) {
+          FILoc = SM.getInstantiationLoc(FILoc);
           bool IsInvalid = false;
           const char *SourcePtr =
             SM.getCharacterData(FILoc.getFileLocWithOffset(-1), &IsInvalid);
index 1a6ef635570a57e031e09d74488f8b13b46cf643..ba45cf28e69486b19ebf1ae3c2080b171ec45155 100644 (file)
@@ -33,9 +33,14 @@ void f1(x, y)
 
 int i0 = { 17 };
 
+#define ONE 1
+#define TWO 2
+
 int test_cond(int y, int fooBar) {
 // CHECK: int x = y ? 1 : 4+fooBar;
   int x = y ? 1 4+foobar;
+// CHECK: x = y ? ONE : TWO;
+  x = y ? ONE TWO;
   return x;
 }