[cfe-commits] r50625 - in /cfe/trunk: lib/Lex/PPExpressions.cpp test/Preprocessor/expr_comma.c
Chris Lattner
sabre at nondot.org
Sun May 4 11:36:18 PDT 2008
Author: lattner
Date: Sun May 4 13:36:18 2008
New Revision: 50625
URL: http://llvm.org/viewvc/llvm-project?rev=50625&view=rev
Log:
Fix the rest of PR2279:
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.
Added:
cfe/trunk/test/Preprocessor/expr_comma.c
Modified:
cfe/trunk/lib/Lex/PPExpressions.cpp
Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=50625&r1=50624&r2=50625&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Sun May 4 13:36:18 2008
@@ -328,9 +328,9 @@
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 @@
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: {
Added: cfe/trunk/test/Preprocessor/expr_comma.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/expr_comma.c?rev=50625&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/expr_comma.c (added)
+++ cfe/trunk/test/Preprocessor/expr_comma.c Sun May 4 13:36:18 2008
@@ -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
More information about the cfe-commits
mailing list