re PR c/456 (constant expressions constraints (gcc.dg/c90-const-expr-1))
authorJoseph Myers <jsm@polyomino.org.uk>
Wed, 11 Feb 2004 23:50:45 +0000 (23:50 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Wed, 11 Feb 2004 23:50:45 +0000 (23:50 +0000)
PR c/456
* cppexp.c (num_binary_op): Don't allow comma operators in #if
constant expressions at all outside C99 mode if pedantic.

testsuite:
* gcc.dg/cpp/c90-if-comma-1.c, gcc.dg/cpp/c99-if-comma-1.c:
New tests.

From-SVN: r77676

gcc/ChangeLog
gcc/cppexp.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/c90-if-comma-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/c99-if-comma-1.c [new file with mode: 0644]

index 22d06d6ee8a3cf8eb5e19851aa088ea490288c53..6f2774bd715ce6d54b2e98a4fecca6668a8beb98 100644 (file)
@@ -1,3 +1,9 @@
+2004-02-11  Joseph S. Myers  <jsm@polyomino.org.uk>
+
+       PR c/456
+       * cppexp.c (num_binary_op): Don't allow comma operators in #if
+       constant expressions at all outside C99 mode if pedantic.
+
 2004-02-11  Uros Bizjak  <uros@kss-loka.si>
 
        * optabs.h (enum optab_index): Add new OTI_log10 and OTI_log2.
index c6f1f1d39a5ff8ef2e2f73bb94f92c54c2c0c510..5603f5bd58a143eafbba89a781af760122a3e7fc 100644 (file)
@@ -1347,7 +1347,8 @@ num_binary_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
 
       /* Comma.  */
     default: /* case CPP_COMMA: */
-      if (CPP_PEDANTIC (pfile) && !pfile->state.skip_eval)
+      if (CPP_PEDANTIC (pfile) && (!CPP_OPTION (pfile, c99)
+                                  || !pfile->state.skip_eval))
        cpp_error (pfile, CPP_DL_PEDWARN,
                   "comma operator in operand of #if");
       lhs = rhs;
index 7c1aa663a8fc7642cf876650263b2735031f40df..140302bb11d6e251d0f56af69979348d0738c300 100644 (file)
@@ -1,3 +1,9 @@
+2004-02-11  Joseph S. Myers  <jsm@polyomino.org.uk>
+
+       PR c/456
+       * gcc.dg/cpp/c90-if-comma-1.c, gcc.dg/cpp/c99-if-comma-1.c: New
+       tests.
+
 2004-02-11  Uros Bizjak  <uros@kss-loka.si>
 
        * gcc.dg/builtins-33.c: New test.
diff --git a/gcc/testsuite/gcc.dg/cpp/c90-if-comma-1.c b/gcc/testsuite/gcc.dg/cpp/c90-if-comma-1.c
new file mode 100644 (file)
index 0000000..c00403f
--- /dev/null
@@ -0,0 +1,11 @@
+/* Test for commas in constant expressions in #if: not permitted in C90
+   but permitted in unevaluated subexpressions in C99.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do preprocess } */
+/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
+
+#if (1, 2) /* { dg-error "comma" "evaluated comma" } */
+#endif
+
+#if 1 || (1, 2) /* { dg-error "comma" "unevaluated comma" } */
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/c99-if-comma-1.c b/gcc/testsuite/gcc.dg/cpp/c99-if-comma-1.c
new file mode 100644 (file)
index 0000000..cb8eb6f
--- /dev/null
@@ -0,0 +1,11 @@
+/* Test for commas in constant expressions in #if: not permitted in C90
+   but permitted in unevaluated subexpressions in C99.  */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do preprocess } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+#if (1, 2) /* { dg-error "comma" "evaluated comma" } */
+#endif
+
+#if 1 || (1, 2)
+#endif