OSDN Git Service

gcc/testsuite
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 6 May 2008 17:15:07 +0000 (17:15 +0000)
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 6 May 2008 17:15:07 +0000 (17:15 +0000)
PR preprocessor/35313, PR preprocessor/36088:
* gcc.dg/cpp/pr35313.c: New file.
* gcc.dg/cpp/if-oppr.c: Remove test for ',' in a conditional
expression.
* gcc.dg/cpp/if-oppr2.c: New file.
libcpp
PR preprocessor/35313, PR preprocessor/36088:
* expr.c (optab) <QUERY, COMMA>: Set precedence to 4.
(reduce) <case CPP_QUERY>: Special case CPP_COMMA and CPP_COLON.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@134989 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/if-oppr.c
gcc/testsuite/gcc.dg/cpp/if-oppr2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/pr35313.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/expr.c

index e5bf09b..4aacdf2 100644 (file)
@@ -1,3 +1,11 @@
+2008-05-06  Tom Tromey  <tromey@redhat.com>
+
+       PR preprocessor/35313, PR preprocessor/36088:
+       * gcc.dg/cpp/pr35313.c: New file.
+       * gcc.dg/cpp/if-oppr.c: Remove test for ',' in a conditional
+       expression.
+       * gcc.dg/cpp/if-oppr2.c: New file.
+
 2008-05-06  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/36117
 2008-05-06  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/36117
index 9c4910f..a46a815 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+/* Copyright (C) 2000, 2008 Free Software Foundation, Inc.  */
 
 /* Test the full range of preprocessor operator precedence.  Each
    operator is tested with one of immediately higher precedence to
 
 /* Test the full range of preprocessor operator precedence.  Each
    operator is tested with one of immediately higher precedence to
 #else
 #endif
 
 #else
 #endif
 
-/* , not higher than ?.  This is not a syntax error if it is.  */
-#if 1 ? 0, 1: 1        /* { dg-error "without" "? higher precedence than ," } */
-#error
-#endif
-
 /* : strictly higher than ?.  This would give a syntax error otherwise.  */
 #if 0 ? 0 : 1 ? 1 : 1
 #endif
 /* : strictly higher than ?.  This would give a syntax error otherwise.  */
 #if 0 ? 0 : 1 ? 1 : 1
 #endif
diff --git a/gcc/testsuite/gcc.dg/cpp/if-oppr2.c b/gcc/testsuite/gcc.dg/cpp/if-oppr2.c
new file mode 100644 (file)
index 0000000..bcfe7cc
--- /dev/null
@@ -0,0 +1,10 @@
+/* Copyright (C) 2008 Free Software Foundation, Inc.  */
+
+/* Another test of operator precedence.  */
+
+/* { dg-do preprocess } */
+/* { dg-options "" } */
+
+#if 1 ? 2 : 3 , 0
+#error
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/pr35313.c b/gcc/testsuite/gcc.dg/cpp/pr35313.c
new file mode 100644 (file)
index 0000000..e12636e
--- /dev/null
@@ -0,0 +1,11 @@
+/* Test two failing cases for libcpp parser.  From PRs 35313, 36088*/
+/* { dg-do preprocess } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+extern int x;
+
+#if 0 ? 3,4 : 2
+#endif
+
+#if 1 ? 0 : 1 ? 1/0 : 1/0
+#endif
index 25fc09d..b86e22e 100644 (file)
@@ -1,3 +1,9 @@
+2008-05-06  Tom Tromey  <tromey@redhat.com>
+
+       PR preprocessor/35313, PR preprocessor/36088:
+       * expr.c (optab) <QUERY, COMMA>: Set precedence to 4.
+       (reduce) <case CPP_QUERY>: Special case CPP_COMMA and CPP_COLON.
+
 2008-05-04  David S. Miller  <davem@davemloft.net>
 
        * configure.ac (sparc*-*-*): Always set need_64bit_hwint to yes.
 2008-05-04  David S. Miller  <davem@davemloft.net>
 
        * configure.ac (sparc*-*-*): Always set need_64bit_hwint to yes.
index 00149b2..af0e259 100644 (file)
@@ -1,6 +1,6 @@
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
 /* Parse C expressions for cpplib.
    Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-   2002, 2004 Free Software Foundation.
+   2002, 2004, 2008 Free Software Foundation.
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
    Contributed by Per Bothner, 1994.
 
 This program is free software; you can redistribute it and/or modify it
@@ -809,9 +809,11 @@ static const struct cpp_operator
   /* COMPL */          {16, NO_L_OPERAND},
   /* AND_AND */                {6, LEFT_ASSOC},
   /* OR_OR */          {5, LEFT_ASSOC},
   /* COMPL */          {16, NO_L_OPERAND},
   /* AND_AND */                {6, LEFT_ASSOC},
   /* OR_OR */          {5, LEFT_ASSOC},
-  /* QUERY */          {3, 0},
+  /* Note that QUERY, COLON, and COMMA must have the same precedence.
+     However, there are some special cases for these in reduce().  */
+  /* QUERY */          {4, 0},
   /* COLON */          {4, LEFT_ASSOC | CHECK_PROMOTION},
   /* COLON */          {4, LEFT_ASSOC | CHECK_PROMOTION},
-  /* COMMA */          {2, LEFT_ASSOC},
+  /* COMMA */          {4, LEFT_ASSOC},
   /* OPEN_PAREN */     {1, NO_L_OPERAND},
   /* CLOSE_PAREN */    {0, 0},
   /* EOF */            {0, 0},
   /* OPEN_PAREN */     {1, NO_L_OPERAND},
   /* CLOSE_PAREN */    {0, 0},
   /* EOF */            {0, 0},
@@ -1101,6 +1103,9 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
          continue;
 
        case CPP_QUERY:
          continue;
 
        case CPP_QUERY:
+         /* COMMA and COLON should not reduce a QUERY operator.  */
+         if (op == CPP_COMMA || op == CPP_COLON)
+           return top;
          cpp_error (pfile, CPP_DL_ERROR, "'?' without following ':'");
          return 0;
 
          cpp_error (pfile, CPP_DL_ERROR, "'?' without following ':'");
          return 0;