summaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-17 09:20:51 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-17 09:20:51 +0000
commit655109c8a29eb7ea5c4254f01a6367dc07d921b0 (patch)
treee4dd6ebe816e96ed4438c19008d235f68f8c19fc /gcc/testsuite
parent6a4e0750ccf988d9a9684da0bf9a858f358e706c (diff)
downloadgcc-655109c8a29eb7ea5c4254f01a6367dc07d921b0.tar.gz
* c-typeck.c (parser_build_binary_op): Condition warnings for
X<=Y<=Z on -Wparentheses instead of -Wextra. * doc/invoke.texi: Update. Document that most of -Wparentheses is supported for C only. testsuite: * gcc.dg/Wparentheses-2.c, gcc.dg/Wparentheses-3.c, gcc.dg/Wparentheses-4.c, Wparentheses-5.c, Wparentheses-6.c, Wparentheses-7.c, Wparentheses-8.c, Wparentheses-9.c: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@84860 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/Wparentheses-2.c67
-rw-r--r--gcc/testsuite/gcc.dg/Wparentheses-3.c68
-rw-r--r--gcc/testsuite/gcc.dg/Wparentheses-4.c85
-rw-r--r--gcc/testsuite/gcc.dg/Wparentheses-5.c31
-rw-r--r--gcc/testsuite/gcc.dg/Wparentheses-6.c121
-rw-r--r--gcc/testsuite/gcc.dg/Wparentheses-7.c121
-rw-r--r--gcc/testsuite/gcc.dg/Wparentheses-8.c103
-rw-r--r--gcc/testsuite/gcc.dg/Wparentheses-9.c61
9 files changed, 663 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bdf36eaea29..d2c90e29f99 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2004-07-17 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ * gcc.dg/Wparentheses-2.c, gcc.dg/Wparentheses-3.c,
+ gcc.dg/Wparentheses-4.c, Wparentheses-5.c, Wparentheses-6.c,
+ Wparentheses-7.c, Wparentheses-8.c, Wparentheses-9.c: New tests.
+
2004-07-16 Richard Henderson <rth@redhat.com>
* gcc.c-torture/compile/20020210-1.c: Remove XFAIL.
diff --git a/gcc/testsuite/gcc.dg/Wparentheses-2.c b/gcc/testsuite/gcc.dg/Wparentheses-2.c
new file mode 100644
index 00000000000..e4110a8ceed
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wparentheses-2.c
@@ -0,0 +1,67 @@
+/* Test operation of -Wparentheses. Warnings for X<=Y<=Z should be
+ there rather than hidden in -Wextra. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+
+/* { dg-do compile } */
+/* { dg-options "-Wparentheses" } */
+
+int foo (int);
+
+int
+bar (int a, int b, int c)
+{
+ foo (a <= b <= c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((a <= b) <= c);
+ foo (a <= (b <= c));
+ foo (1 <= 2 <= c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 <= 2) <= c);
+ foo (1 <= (2 <= c));
+ foo (1 <= 2 <= 3); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 <= 2) <= 3);
+ foo (1 <= (2 <= 3));
+ foo (a > b > c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((a > b) > c);
+ foo (a > (b > c));
+ foo (1 > 2 > c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 > 2) > c);
+ foo (1 > (2 > c));
+ foo (1 > 2 > 3); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 > 2) > 3);
+ foo (1 > (2 > 3));
+ foo (a < b <= c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((a < b) <= c);
+ foo (a < (b <= c));
+ foo (1 < 2 <= c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 < 2) <= c);
+ foo (1 < (2 <= c));
+ foo (1 < 2 <= 3); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 < 2) <= 3);
+ foo (1 < (2 <= 3));
+ foo (a <= b > c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((a <= b) > c);
+ foo (a <= (b > c));
+ foo (1 <= 2 > c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 <= 2) > c);
+ foo (1 <= (2 > c));
+ foo (1 <= 2 > 3); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 <= 2) > 3);
+ foo (1 <= (2 > 3));
+ foo (a <= b == c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((a <= b) == c);
+ foo (a <= (b == c));
+ foo (1 <= 2 == c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 <= 2) == c);
+ foo (1 <= (2 == c));
+ foo (1 <= 2 == 3); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 <= 2) == 3);
+ foo (1 <= (2 == 3));
+ foo (a != b != c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((a != b) != c);
+ foo (a != (b != c));
+ foo (1 != 2 != c); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 != 2) != c);
+ foo (1 != (2 != c));
+ foo (1 != 2 != 3); /* { dg-warning "comparison" "correct warning" } */
+ foo ((1 != 2) != 3);
+ foo (1 != (2 != 3));
+}
diff --git a/gcc/testsuite/gcc.dg/Wparentheses-3.c b/gcc/testsuite/gcc.dg/Wparentheses-3.c
new file mode 100644
index 00000000000..64899887c38
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wparentheses-3.c
@@ -0,0 +1,68 @@
+/* Test operation of -Wparentheses. Warnings for assignments used as
+ truth-values. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+
+/* { dg-do compile } */
+/* { dg-options "-Wparentheses -std=gnu99" } */
+
+int foo (int);
+
+int a, b, c;
+_Bool d;
+
+int
+bar (void)
+{
+ if (a = b) /* { dg-warning "assignment" "correct warning" } */
+ foo (0);
+ if ((a = b))
+ foo (1);
+ if (a = a) /* { dg-warning "assignment" "correct warning" } */
+ foo (2);
+ if ((a = a))
+ foo (3);
+ if (b = c) /* { dg-warning "assignment" "correct warning" } */
+ foo (4);
+ else
+ foo (5);
+ if ((b = c))
+ foo (6);
+ else
+ foo (7);
+ if (b = b) /* { dg-warning "assignment" "correct warning" } */
+ foo (8);
+ else
+ foo (9);
+ if ((b = b))
+ foo (10);
+ else
+ foo (11);
+ while (c = b) /* { dg-warning "assignment" "correct warning" } */
+ foo (12);
+ while ((c = b))
+ foo (13);
+ while (c = c) /* { dg-warning "assignment" "correct warning" } */
+ foo (14);
+ while ((c = c))
+ foo (15);
+ do foo (16); while (a = b); /* { dg-warning "assignment" "correct warning" } */
+ do foo (17); while ((a = b));
+ do foo (18); while (a = a); /* { dg-warning "assignment" "correct warning" } */
+ do foo (19); while ((a = a));
+ for (;c = b;) /* { dg-warning "assignment" "correct warning" } */
+ foo (20);
+ for (;(c = b);)
+ foo (21);
+ for (;c = c;) /* { dg-warning "assignment" "correct warning" } */
+ foo (22);
+ for (;(c = c);)
+ foo (23);
+ d = a = b; /* { dg-warning "assignment" "correct warning" } */
+ foo (24);
+ d = (a = b);
+ foo (25);
+ d = a = a; /* { dg-warning "assignment" "correct warning" } */
+ foo (26);
+ d = (a = a);
+ foo (27);
+}
diff --git a/gcc/testsuite/gcc.dg/Wparentheses-4.c b/gcc/testsuite/gcc.dg/Wparentheses-4.c
new file mode 100644
index 00000000000..dfc9d1008ef
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wparentheses-4.c
@@ -0,0 +1,85 @@
+/* Test operation of -Wparentheses. Precedence warnings. + or -
+ inside shift. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+
+/* { dg-do compile } */
+/* { dg-options "-Wparentheses" } */
+
+int foo (int);
+
+int
+bar (int a, int b, int c)
+{
+ foo (a + b << c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a + b) << c);
+ foo (a + (b << c));
+ foo (1 + 2 << c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) << c);
+ foo (1 + (2 << c));
+ foo (1 + 2 << 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) << 3);
+ foo (1 + (2 << 3));
+ foo (a << b + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a << b) + c);
+ foo (a << (b + c));
+ foo (1 << 2 + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 << 2) + c);
+ foo (1 << (2 + c));
+ foo (1 << 2 + 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 << 2) + 3);
+ foo (1 << (2 + 3));
+ foo (a + b >> c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a + b) >> c);
+ foo (a + (b >> c));
+ foo (1 + 2 >> c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) >> c);
+ foo (1 + (2 >> c));
+ foo (1 + 2 >> 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) >> 3);
+ foo (1 + (2 >> 3));
+ foo (a >> b + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a >> b) + c);
+ foo (a >> (b + c));
+ foo (1 >> 2 + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 >> 2) + c);
+ foo (1 >> (2 + c));
+ foo (1 >> 2 + 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 >> 2) + 3);
+ foo (1 >> (2 + 3));
+ foo (a - b << c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a - b) << c);
+ foo (a - (b << c));
+ foo (6 - 5 << c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((6 - 5) << c);
+ foo (6 - (5 << c));
+ foo (6 - 5 << 4); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((6 - 5) << 4);
+ foo (6 - (5 << 4));
+ foo (a << b - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a << b) - c);
+ foo (a << (b - c));
+ foo (6 << 5 - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((6 << 5) - c);
+ foo (6 << (5 - c));
+ foo (6 << 5 - 4); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((6 << 5) - 4);
+ foo (6 << (5 - 4));
+ foo (a - b >> c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a - b) >> c);
+ foo (a - (b >> c));
+ foo (6 - 5 >> c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((6 - 5) >> c);
+ foo (6 - (5 >> c));
+ foo (6 - 5 >> 4); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((6 - 5) >> 4);
+ foo (6 - (5 >> 4));
+ foo (a >> b - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a >> b) - c);
+ foo (a >> (b - c));
+ foo (6 >> 5 - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((6 >> 5) - c);
+ foo (6 >> (5 - c));
+ foo (6 >> 5 - 4); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((6 >> 5) - 4);
+ foo (6 >> (5 - 4));
+}
diff --git a/gcc/testsuite/gcc.dg/Wparentheses-5.c b/gcc/testsuite/gcc.dg/Wparentheses-5.c
new file mode 100644
index 00000000000..be12f73f1c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wparentheses-5.c
@@ -0,0 +1,31 @@
+/* Test operation of -Wparentheses. Precedence warnings. && inside
+ ||. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+
+/* { dg-do compile } */
+/* { dg-options "-Wparentheses" } */
+
+int foo (int);
+
+int
+bar (int a, int b, int c)
+{
+ foo (a && b || c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a && b) || c);
+ foo (a && (b || c));
+ foo (1 && 2 || c); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */
+ foo ((1 && 2) || c);
+ foo (1 && (2 || c));
+ foo (1 && 2 || 3); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */
+ foo ((1 && 2) || 3);
+ foo (1 && (2 || 3));
+ foo (a || b && c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a || b) && c);
+ foo (a || (b && c));
+ foo (1 || 2 && c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 || 2) && c);
+ foo (1 || (2 && c));
+ foo (1 || 2 && 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 || 2) && 3);
+ foo (1 || (2 && 3));
+}
diff --git a/gcc/testsuite/gcc.dg/Wparentheses-6.c b/gcc/testsuite/gcc.dg/Wparentheses-6.c
new file mode 100644
index 00000000000..2d2cc161394
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wparentheses-6.c
@@ -0,0 +1,121 @@
+/* Test operation of -Wparentheses. Precedence warnings. & or ^ or +
+ or - or comparison inside |. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+
+/* { dg-do compile } */
+/* { dg-options "-Wparentheses" } */
+
+int foo (int);
+
+int
+bar (int a, int b, int c)
+{
+ foo (a & b | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a & b) | c);
+ foo (a & (b | c));
+ foo (1 & 2 | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) | c);
+ foo (1 & (2 | c));
+ foo (1 & 2 | 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) | 3);
+ foo (1 & (2 | 3));
+ foo (a | b & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a | b) & c);
+ foo (a | (b & c));
+ foo (1 | 2 & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) & c);
+ foo (1 | (2 & c));
+ foo (1 | 2 & 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) & 3);
+ foo (1 | (2 & 3));
+ foo (a ^ b | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a ^ b) | c);
+ foo (a ^ (b | c));
+ foo (1 ^ 2 | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) | c);
+ foo (1 ^ (2 | c));
+ foo (1 ^ 2 | 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) | 3);
+ foo (1 ^ (2 | 3));
+ foo (a | b ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a | b) ^ c);
+ foo (a | (b ^ c));
+ foo (1 | 2 ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) ^ c);
+ foo (1 | (2 ^ c));
+ foo (1 | 2 ^ 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) ^ 3);
+ foo (1 | (2 ^ 3));
+ foo (a + b | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a + b) | c);
+ foo (a + (b | c));
+ foo (1 + 2 | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) | c);
+ foo (1 + (2 | c));
+ foo (1 + 2 | 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) | 3);
+ foo (1 + (2 | 3));
+ foo (a | b + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a | b) + c);
+ foo (a | (b + c));
+ foo (1 | 2 + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) + c);
+ foo (1 | (2 + c));
+ foo (1 | 2 + 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) + 3);
+ foo (1 | (2 + 3));
+ foo (a - b | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a - b) | c);
+ foo (a - (b | c));
+ foo (1 - 2 | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 - 2) | c);
+ foo (1 - (2 | c));
+ foo (1 - 2 | 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 - 2) | 3);
+ foo (1 - (2 | 3));
+ foo (a | b - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a | b) - c);
+ foo (a | (b - c));
+ foo (1 | 2 - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) - c);
+ foo (1 | (2 - c));
+ foo (1 | 2 - 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) - 3);
+ foo (1 | (2 - 3));
+ foo (a > b | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a > b) | c);
+ foo (a > (b | c));
+ foo (1 > 2 | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 > 2) | c);
+ foo (1 > (2 | c));
+ foo (1 > 2 | 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 > 2) | 3);
+ foo (1 > (2 | 3));
+ foo (a | b > c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a | b) > c);
+ foo (a | (b > c));
+ foo (1 | 2 > c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) > c);
+ foo (1 | (2 > c));
+ foo (1 | 2 > 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) > 3);
+ foo (1 | (2 > 3));
+ foo (a <= b | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a <= b) | c);
+ foo (a <= (b | c));
+ foo (1 <= 2 | c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 <= 2) | c);
+ foo (1 <= (2 | c));
+ foo (1 <= 2 | 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 <= 2) | 3);
+ foo (1 <= (2 | 3));
+ foo (a | b <= c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a | b) <= c);
+ foo (a | (b <= c));
+ foo (1 | 2 <= c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) <= c);
+ foo (1 | (2 <= c));
+ foo (1 | 2 <= 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 | 2) <= 3);
+ foo (1 | (2 <= 3));
+}
diff --git a/gcc/testsuite/gcc.dg/Wparentheses-7.c b/gcc/testsuite/gcc.dg/Wparentheses-7.c
new file mode 100644
index 00000000000..f3516969d23
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wparentheses-7.c
@@ -0,0 +1,121 @@
+/* Test operation of -Wparentheses. Precedence warnings. & or + or -
+ or comparison inside ^. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+
+/* { dg-do compile } */
+/* { dg-options "-Wparentheses" } */
+
+int foo (int);
+
+int
+bar (int a, int b, int c)
+{
+ foo (a & b ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a & b) ^ c);
+ foo (a & (b ^ c));
+ foo (1 & 2 ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) ^ c);
+ foo (1 & (2 ^ c));
+ foo (1 & 2 ^ 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) ^ 3);
+ foo (1 & (2 ^ 3));
+ foo (a ^ b & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a ^ b) & c);
+ foo (a ^ (b & c));
+ foo (1 ^ 2 & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) & c);
+ foo (1 ^ (2 & c));
+ foo (1 ^ 2 & 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) & 3);
+ foo (1 ^ (2 & 3));
+ foo (a + b ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a + b) ^ c);
+ foo (a + (b ^ c));
+ foo (1 + 2 ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) ^ c);
+ foo (1 + (2 ^ c));
+ foo (1 + 2 ^ 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) ^ 3);
+ foo (1 + (2 ^ 3));
+ foo (a ^ b + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a ^ b) + c);
+ foo (a ^ (b + c));
+ foo (1 ^ 2 + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) + c);
+ foo (1 ^ (2 + c));
+ foo (1 ^ 2 + 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) + 3);
+ foo (1 ^ (2 + 3));
+ foo (a - b ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a - b) ^ c);
+ foo (a - (b ^ c));
+ foo (1 - 2 ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 - 2) ^ c);
+ foo (1 - (2 ^ c));
+ foo (1 - 2 ^ 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 - 2) ^ 3);
+ foo (1 - (2 ^ 3));
+ foo (a ^ b - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a ^ b) - c);
+ foo (a ^ (b - c));
+ foo (1 ^ 2 - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) - c);
+ foo (1 ^ (2 - c));
+ foo (1 ^ 2 - 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) - 3);
+ foo (1 ^ (2 - 3));
+ foo (a >= b ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a >= b) ^ c);
+ foo (a >= (b ^ c));
+ foo (1 >= 2 ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 >= 2) ^ c);
+ foo (1 >= (2 ^ c));
+ foo (1 >= 2 ^ 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 >= 2) ^ 3);
+ foo (1 >= (2 ^ 3));
+ foo (a ^ b >= c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a ^ b) >= c);
+ foo (a ^ (b >= c));
+ foo (1 ^ 2 >= c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) >= c);
+ foo (1 ^ (2 >= c));
+ foo (1 ^ 2 >= 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) >= 3);
+ foo (1 ^ (2 >= 3));
+ foo (a == b ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a == b) ^ c);
+ foo (a == (b ^ c));
+ foo (1 == 2 ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 == 2) ^ c);
+ foo (1 == (2 ^ c));
+ foo (1 == 2 ^ 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 == 2) ^ 3);
+ foo (1 == (2 ^ 3));
+ foo (a ^ b == c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a ^ b) == c);
+ foo (a ^ (b == c));
+ foo (1 ^ 2 == c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) == c);
+ foo (1 ^ (2 == c));
+ foo (1 ^ 2 == 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) == 3);
+ foo (1 ^ (2 == 3));
+ foo (a < b ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a < b) ^ c);
+ foo (a < (b ^ c));
+ foo (1 < 2 ^ c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 < 2) ^ c);
+ foo (1 < (2 ^ c));
+ foo (1 < 2 ^ 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 < 2) ^ 3);
+ foo (1 < (2 ^ 3));
+ foo (a ^ b < c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a ^ b) < c);
+ foo (a ^ (b < c));
+ foo (1 ^ 2 < c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) < c);
+ foo (1 ^ (2 < c));
+ foo (1 ^ 2 < 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 ^ 2) < 3);
+ foo (1 ^ (2 < 3));
+}
diff --git a/gcc/testsuite/gcc.dg/Wparentheses-8.c b/gcc/testsuite/gcc.dg/Wparentheses-8.c
new file mode 100644
index 00000000000..ff34ee0a520
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wparentheses-8.c
@@ -0,0 +1,103 @@
+/* Test operation of -Wparentheses. Precedence warnings. + or - or
+ comparison inside &. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+
+/* { dg-do compile } */
+/* { dg-options "-Wparentheses" } */
+
+int foo (int);
+
+int
+bar (int a, int b, int c)
+{
+ foo (a + b & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a + b) & c);
+ foo (a + (b & c));
+ foo (1 + 2 & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) & c);
+ foo (1 + (2 & c));
+ foo (1 + 2 & 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 + 2) & 3);
+ foo (1 + (2 & 3));
+ foo (a & b + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a & b) + c);
+ foo (a & (b + c));
+ foo (1 & 2 + c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) + c);
+ foo (1 & (2 + c));
+ foo (1 & 2 + 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) + 3);
+ foo (1 & (2 + 3));
+ foo (a - b & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a - b) & c);
+ foo (a - (b & c));
+ foo (1 - 2 & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 - 2) & c);
+ foo (1 - (2 & c));
+ foo (1 - 2 & 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 - 2) & 3);
+ foo (1 - (2 & 3));
+ foo (a & b - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a & b) - c);
+ foo (a & (b - c));
+ foo (1 & 2 - c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) - c);
+ foo (1 & (2 - c));
+ foo (1 & 2 - 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) - 3);
+ foo (1 & (2 - 3));
+ foo (a < b & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a < b) & c);
+ foo (a < (b & c));
+ foo (1 < 2 & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 < 2) & c);
+ foo (1 < (2 & c));
+ foo (1 < 2 & 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 < 2) & 3);
+ foo (1 < (2 & 3));
+ foo (a & b < c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a & b) < c);
+ foo (a & (b < c));
+ foo (1 & 2 < c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) < c);
+ foo (1 & (2 < c));
+ foo (1 & 2 < 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) < 3);
+ foo (1 & (2 < 3));
+ foo (a == b & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a == b) & c);
+ foo (a == (b & c));
+ foo (1 == 2 & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 == 2) & c);
+ foo (1 == (2 & c));
+ foo (1 == 2 & 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 == 2) & 3);
+ foo (1 == (2 & 3));
+ foo (a & b == c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a & b) == c);
+ foo (a & (b == c));
+ foo (1 & 2 == c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) == c);
+ foo (1 & (2 == c));
+ foo (1 & 2 == 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) == 3);
+ foo (1 & (2 == 3));
+ foo (a != b & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a != b) & c);
+ foo (a != (b & c));
+ foo (1 != 2 & c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 != 2) & c);
+ foo (1 != (2 & c));
+ foo (1 != 2 & 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 != 2) & 3);
+ foo (1 != (2 & 3));
+ foo (a & b != c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((a & b) != c);
+ foo (a & (b != c));
+ foo (1 & 2 != c); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) != c);
+ foo (1 & (2 != c));
+ foo (1 & 2 != 3); /* { dg-warning "parentheses" "correct warning" } */
+ foo ((1 & 2) != 3);
+ foo (1 & (2 != 3));
+}
diff --git a/gcc/testsuite/gcc.dg/Wparentheses-9.c b/gcc/testsuite/gcc.dg/Wparentheses-9.c
new file mode 100644
index 00000000000..0fff6ea1aa3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wparentheses-9.c
@@ -0,0 +1,61 @@
+/* Test operation of -Wparentheses. Warnings for ambiguous else. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+
+/* { dg-do compile } */
+/* { dg-options "-Wparentheses" } */
+
+int foo (int);
+
+int a, b, c;
+
+int
+bar (void)
+{
+ if (a)
+ foo (0);
+ if (b)
+ foo (1);
+ else
+ foo (2);
+ if (c) /* { dg-warning "ambiguous" "correct warning" } */
+ if (a)
+ foo (3);
+ else
+ foo (4);
+ if (a)
+ if (c)
+ foo (5);
+ if (a)
+ if (b) /* { dg-warning "ambiguous" "correct warning" } */
+ if (c)
+ foo (6);
+ else
+ foo (7);
+ if (a) /* { dg-warning "ambiguous" "correct warning" } */
+ if (b)
+ if (c)
+ foo (8);
+ else
+ foo (9);
+ else
+ foo (10);
+ if (a)
+ if (b)
+ if (c)
+ foo (11);
+ else
+ foo (12);
+ else
+ foo (13);
+ else
+ foo (14);
+ if (a) {
+ if (b)
+ if (c)
+ foo (15);
+ else
+ foo (16);
+ else
+ foo (17);
+ }
+}