re PR c++/18047 (Wrong precedence between equality (==, !=) and < operators)
authorPaolo Bonzini <bonzini@gnu.org>
Tue, 19 Oct 2004 12:40:31 +0000 (12:40 +0000)
committerPaolo Bonzini <bonzini@gcc.gnu.org>
Tue, 19 Oct 2004 12:40:31 +0000 (12:40 +0000)
2004-10-19  Paolo Bonzini  <bonzini@gnu.org>

PR c++/18047
* parser.c (enum cp_parser_prec): Give relational expressions
a higher precedence than equality expressions.

2004-10-19  Paolo Bonzini  <bonzini@gnu.org>

PR c++/18047

* g++.dg/parse/expr3.C: New test.

From-SVN: r89272

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/expr3.C [new file with mode: 0644]

index fa85757b919c4af009403ea9d5e99793984f4d26..325fbf3db0f997945e38230189be588166155224 100644 (file)
@@ -1,3 +1,9 @@
+2004-10-19  Paolo Bonzini  <bonzini@gnu.org>
+
+       PR c++/18047
+       * parser.c (enum cp_parser_prec): Give relational expressions
+       a higher precedence than equality expressions.
+
 2004-10-15  Nathan Sidwell  <nathan@codesourcery.com>
 
        * cp-tree.h (UNIQUELY_DERIVED_FROM_P): Adjust lookup_base call.
index 76738262e7c16464563eba8803beee7945a72cea..6dac467f977d66e3294946a91be1a999bc9b283d 100644 (file)
@@ -1074,8 +1074,8 @@ enum cp_parser_prec
   PREC_INCLUSIVE_OR_EXPRESSION,
   PREC_EXCLUSIVE_OR_EXPRESSION,
   PREC_AND_EXPRESSION,
-  PREC_RELATIONAL_EXPRESSION,
   PREC_EQUALITY_EXPRESSION,
+  PREC_RELATIONAL_EXPRESSION,
   PREC_SHIFT_EXPRESSION,
   PREC_ADDITIVE_EXPRESSION,
   PREC_MULTIPLICATIVE_EXPRESSION,
index 0254a749d12803dcebb2dc2b2261b97185a87294..289420580b270bbf0764a753e617d2fec47bcead 100644 (file)
@@ -1,3 +1,9 @@
+2004-10-19  Paolo Bonzini  <bonzini@gnu.org>
+
+       PR c++/18047
+
+       * g++.dg/parse/expr3.C: New test.
+
 2004-10-18  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * gcc.dg/smod-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/parse/expr3.C b/gcc/testsuite/g++.dg/parse/expr3.C
new file mode 100644 (file)
index 0000000..95d332f
--- /dev/null
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* PR/18047  Test that operators have the right precedence.  */
+/* by bonzini@gnu.org */
+
+#define test(lower, higher, a, b, c, d) \
+  test_(lower, higher, a, b, c, d, __LINE__)
+
+#define test_(lower, higher, a, b, c, d, line)\
+   test__(lower, higher, a, b, c, d, line)
+
+/* The first declaration tests that the parentheses are added correctly
+   by the expression parser.  The second tests that the two possible
+   orderings of precedences do give different results.  */
+#define test__(lower, higher, a, b, c, d, line) \
+  char test##line[ \
+    (a higher b lower c higher d) == \
+    ((a higher b) lower (c higher d)) \
+    ? 1 : -1]; \
+  char doublecheck##line[ \
+    (a higher b lower c higher d) == \
+    (a higher (b lower c) higher d) \
+    ? -1 : 1];
+
+test (||, &&, 1, 1, 0, 0)
+test (&&, |, 5, 1, 1, 19)
+test (|, ^, 1, 2, 2, 1)
+test (^, &, 1, 3, 2, 6)
+test (&, ==, 1, 3, 2, 0)
+test (==, <, 2, 0, 0, 0)
+test (<, <<, 2, 3, 6, 8)
+test (<<, +, 2, 3, 4, 5)
+test (+, *, 2, 6, 9, 13)