This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PR c++/36069 Strange "warning: suggest parentheses around assignment used as truth value" with volatile/non volatile bools
- From: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Cc: Mark Mitchell <mark at codesourcery dot com>, Jason Merrill <jason at redhat dot com>
- Date: Wed, 5 Aug 2009 00:35:28 +0200
- Subject: PR c++/36069 Strange "warning: suggest parentheses around assignment used as truth value" with volatile/non volatile bools
Bootstrapped and regression tested on x86_64-linux-gnu.
OK for trunk?
2009-08-05 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c++/36069
* typeck.c (convert_for_assignment): Do not warn for any boolean
variant. Use explicit location.
testsuite/
* g++.dg/warn/pr36069.C: New.
Index: gcc/testsuite/g++.dg/warn/pr36069.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr36069.C (revision 0)
+++ gcc/testsuite/g++.dg/warn/pr36069.C (revision 0)
@@ -0,0 +1,16 @@
+// PR c++/36069 Strange "warning: suggest parentheses around
+// assignment used as truth value" with volatile/non volatile bools
+// { dg-do compile }
+// { dg-options "-Wparentheses" }
+struct foo {
+ bool a;
+ volatile bool b,c;
+ foo() { a = b = c = false; } // { dg-bogus "parentheses" }
+};
+
+int main() {
+ bool a;
+ volatile bool b,c;
+ a = b = c = false; // { dg-bogus "parentheses" }
+ foo A;
+}
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c (revision 149790)
+++ gcc/cp/typeck.c (working copy)
@@ -6766,15 +6766,18 @@ convert_for_assignment (tree type, tree
does not. */
if (warn_parentheses
&& type == boolean_type_node
&& TREE_CODE (rhs) == MODIFY_EXPR
&& !TREE_NO_WARNING (rhs)
- && TREE_TYPE (rhs) != boolean_type_node
+ && TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE
&& (complain & tf_warning))
{
- warning (OPT_Wparentheses,
- "suggest parentheses around assignment used as truth value");
+ location_t loc = EXPR_HAS_LOCATION (rhs)
+ ? EXPR_LOCATION (rhs) : input_location;
+
+ warning_at (loc, OPT_Wparentheses,
+ "suggest parentheses around assignment used as truth value");
TREE_NO_WARNING (rhs) = 1;
}
return perform_implicit_conversion_flags (strip_top_quals (type), rhs,
complain, flags);