aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorJoseph Myers <jsm@polyomino.org.uk>2004-07-17 10:20:51 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2004-07-17 10:20:51 +0100
commit3e3970a27611d6cf2c5d8cfaa73e9e17f38b530c (patch)
treee4dd6ebe816e96ed4438c19008d235f68f8c19fc /gcc/testsuite
parent10c383a4be1ee140d5387bb0448ffb160e97896d (diff)
downloadgcc-3e3970a27611d6cf2c5d8cfaa73e9e17f38b530c.zip
gcc-3e3970a27611d6cf2c5d8cfaa73e9e17f38b530c.tar.gz
gcc-3e3970a27611d6cf2c5d8cfaa73e9e17f38b530c.tar.bz2
c-typeck.c (parser_build_binary_op): Condition warnings for X<=Y<=Z on -Wparentheses instead of -Wextra.
* 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. From-SVN: r84860
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 bdf36ea..d2c90e2 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 0000000..e4110a8
--- /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 0000000..6489988
--- /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 0000000..dfc9d10
--- /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 0000000..be12f73
--- /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 0000000..2d2cc16
--- /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 0000000..f351696
--- /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 0000000..ff34ee0
--- /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 0000000..0fff6ea
--- /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);
+ }
+}