]> granicus.if.org Git - clang/commitdiff
Fix the rest of PR2279:
authorChris Lattner <sabre@nondot.org>
Sun, 4 May 2008 18:36:18 +0000 (18:36 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 4 May 2008 18:36:18 +0000 (18:36 +0000)
a) correct rejection of ',' in pp expressions.
b) the precedence of ',' was wrong w.r.t. ?:.

Thanks again to Neil for finding these and providing testcases.

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

lib/Lex/PPExpressions.cpp
test/Preprocessor/expr_comma.c [new file with mode: 0644]

index 6343a3c09839646356673224bacd524f13ca46b7..3c0bf5c59c876249c71d0a1edcf6681add977b5b 100644 (file)
@@ -328,9 +328,9 @@ static unsigned getPrecedence(tok::TokenKind Kind) {
   case tok::pipe:                 return 7;
   case tok::ampamp:               return 6;
   case tok::pipepipe:             return 5;
-  case tok::question:             return 4;
-  case tok::colon:                return 3;
-  case tok::comma:                return 2;
+  case tok::comma:                return 4;
+  case tok::question:             return 3;
+  case tok::colon:                return 2;
   case tok::r_paren:              return 0;   // Lowest priority, end of expr.
   case tok::eom:                  return 0;   // Lowest priority, end of macro.
   }
@@ -543,7 +543,10 @@ static bool EvaluateDirectiveSubExpr(llvm::APSInt &LHS, unsigned MinPrec,
       Res.setIsUnsigned(false);  // C99 6.5.14p3, result is always int (signed)
       break;
     case tok::comma:
-      PP.Diag(OpToken, diag::ext_pp_comma_expr);
+      // Comma is invalid in pp expressions in c89/c++ mode, but is valid in C99
+      // if not being evaluated.
+      if (!PP.getLangOptions().C99 || ValueLive)
+        PP.Diag(OpToken, diag::ext_pp_comma_expr);
       Res = RHS; // LHS = LHS,RHS -> RHS.
       break; 
     case tok::question: {
diff --git a/test/Preprocessor/expr_comma.c b/test/Preprocessor/expr_comma.c
new file mode 100644 (file)
index 0000000..5507272
--- /dev/null
@@ -0,0 +1,10 @@
+// Comma is not allowed in C89
+// RUN: not clang -E %s -std=c89 -pedantic-errors 
+
+// Comma is allowed if unevaluated in C99
+// RUN: clang -E %s -std=c99 -pedantic-errors 
+
+// PR2279
+
+#if 0? 1,2:3
+#endif