re PR c/71926 (wrong location for -Wparentheses warning)
authorMarek Polacek <polacek@redhat.com>
Fri, 29 Jul 2016 17:39:39 +0000 (17:39 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 29 Jul 2016 17:39:39 +0000 (17:39 +0000)
PR c/71926
* c-common.c (c_common_truthvalue_conversion): Use LOCATION for the
parentheses warning.

* semantics.c (maybe_convert_cond): Use the location of COND for the
parentheses warning.

* g++.dg/warn/Wparentheses-30.C: New test.
* gcc.dg/Wparentheses-14.c: New test.

From-SVN: r238886

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wparentheses-30.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wparentheses-14.c [new file with mode: 0644]

index 705d00cee0e29441bb2357cee0624b961d3ae8a7..aed494a5af1fc2c58bcd2616733b60858986fb67 100644 (file)
@@ -1,5 +1,9 @@
 2016-07-29  Marek Polacek  <polacek@redhat.com>
 
+       PR c/71926
+       * c-common.c (c_common_truthvalue_conversion): Use LOCATION for the
+       parentheses warning.
+
        PR c/71574
        * c-common.c (handle_alloc_align_attribute): Also check FUNCTION_DECL.
 
index efd98157a629e45c72258a626451a324e9a78c0e..27031b5e25fb95f59c2b7f1e33e06c4cc91c511a 100644 (file)
@@ -4591,8 +4591,9 @@ c_common_truthvalue_conversion (location_t location, tree expr)
       if (!TREE_NO_WARNING (expr)
          && warn_parentheses)
        {
-         warning (OPT_Wparentheses,
-                  "suggest parentheses around assignment used as truth value");
+         warning_at (location, OPT_Wparentheses,
+                     "suggest parentheses around assignment used as "
+                     "truth value");
          TREE_NO_WARNING (expr) = 1;
        }
       break;
index 71aa08478066658c309a88a27a958f35268e7060..db6e1eb773011f21a4d47a99aeb67b799f7adc7e 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-29  Marek Polacek  <polacek@redhat.com>
+
+       PR c/71926
+       * semantics.c (maybe_convert_cond): Use the location of COND for the
+       parentheses warning.
+
 2016-07-29  Jason Merrill  <jason@redhat.com>
 
        * decl.c (build_enumerator): Tweak diagnostic.
index 63063b84bfc7bab69abb1ea43e8891646e708460..2fe2d091a3a0c0748007149785b024477b431690 100644 (file)
@@ -656,8 +656,8 @@ maybe_convert_cond (tree cond)
       && !TREE_NO_WARNING (cond)
       && warn_parentheses)
     {
-      warning (OPT_Wparentheses,
-              "suggest parentheses around assignment used as truth value");
+      warning_at (EXPR_LOC_OR_LOC (cond, input_location), OPT_Wparentheses,
+                 "suggest parentheses around assignment used as truth value");
       TREE_NO_WARNING (cond) = 1;
     }
 
index e29c07cb8b947a9679467b8fae25a0ac59c17ebd..5cf7c1fbdea9fff745f24e4866a06e024008279f 100644 (file)
        PR c/71573
        * gcc.dg/noncompile/pr71573.c: New test.
 
+       PR c/71926
+       * g++.dg/warn/Wparentheses-30.C: New test.
+       * gcc.dg/Wparentheses-14.c: New test.
+
 2016-07-29  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.dg/pr59833.c: Use dg-add-options ieee.
diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-30.C b/gcc/testsuite/g++.dg/warn/Wparentheses-30.C
new file mode 100644 (file)
index 0000000..ea7c741
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR c/71926 */
+/* { dg-options "-Wparentheses" }  */
+
+int
+f (void)
+{
+  int a = 1, b = 2, c = 3, d = 4;
+  if (a = 2 || (b != 3 && c != 4 && d != 5)) /* { dg-warning "9:suggest parentheses" } */
+    return 1;
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/Wparentheses-14.c b/gcc/testsuite/gcc.dg/Wparentheses-14.c
new file mode 100644 (file)
index 0000000..36dedf7
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR c/71926 */
+/* { dg-options "-Wparentheses" }  */
+
+int
+f (void)
+{
+  int a = 1, b = 2, c = 3, d = 4;
+  if (a = 2 || (b != 3 && c != 4 && d != 5)) /* { dg-warning "7:suggest parentheses" } */
+    return 1;
+  return 0;
+}