From 638fc14f07ae8908141b520b9d11ba364f087018 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 29 Jul 2016 17:39:39 +0000 Subject: [PATCH] re PR c/71926 (wrong location for -Wparentheses warning) 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 | 4 ++++ gcc/c-family/c-common.c | 5 +++-- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/semantics.c | 4 ++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/warn/Wparentheses-30.C | 11 +++++++++++ gcc/testsuite/gcc.dg/Wparentheses-14.c | 11 +++++++++++ 7 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-30.C create mode 100644 gcc/testsuite/gcc.dg/Wparentheses-14.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 705d00cee0e..aed494a5af1 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,5 +1,9 @@ 2016-07-29 Marek Polacek + 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. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index efd98157a62..27031b5e25f 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -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; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 71aa0847806..db6e1eb7730 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-07-29 Marek Polacek + + PR c/71926 + * semantics.c (maybe_convert_cond): Use the location of COND for the + parentheses warning. + 2016-07-29 Jason Merrill * decl.c (build_enumerator): Tweak diagnostic. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 63063b84bfc..2fe2d091a3a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e29c07cb8b9..5cf7c1fbdea 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -11,6 +11,10 @@ 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 * 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 index 00000000000..ea7c74135ab --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-30.C @@ -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 index 00000000000..36dedf71476 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wparentheses-14.c @@ -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; +} -- 2.30.2