aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-05-26 19:59:26 -0400
committerMarek Polacek <polacek@redhat.com>2020-05-29 12:31:49 -0400
commit1f32d5294f51614f5637d81c522fccacc124f141 (patch)
tree8ef2b8bc87d6962b86d876d723d929aa22fa928c /gcc
parent8e915901deb3518d4bef73ea52eab2ece7a2bbf6 (diff)
downloadgcc-1f32d5294f51614f5637d81c522fccacc124f141.zip
gcc-1f32d5294f51614f5637d81c522fccacc124f141.tar.gz
gcc-1f32d5294f51614f5637d81c522fccacc124f141.tar.bz2
c++: Fix bogus -Wparentheses warning [PR95344]
Since r267272, which added location wrappers, cp_fold loses TREE_NO_WARNING on a MODIFY_EXPR that finish_parenthesized_expr set, and that results in a bogus -Wparentheses warning. I.e., previously we had "b = 1" but now we have "VIEW_CONVERT_EXPR<bool>(b) = 1" and cp_fold_maybe_rvalue folds away the location wrapper and so we do 2718 x = fold_build2_loc (loc, code, TREE_TYPE (x), op0, op1); in cp_fold and the flag is lost. PR c++/95344 * cp-gimplify.c (cp_fold) <case MODIFY_EXPR>: Don't set TREE_THIS_VOLATILE here. (cp_fold): Set it here along with TREE_NO_WARNING. * c-c++-common/Wparentheses-2.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/cp-gimplify.c8
-rw-r--r--gcc/testsuite/c-c++-common/Wparentheses-2.c18
2 files changed, 24 insertions, 2 deletions
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 53d715d..d6723e4 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -2744,8 +2744,6 @@ cp_fold (tree x)
else
x = org_x;
}
- if (code == MODIFY_EXPR && TREE_CODE (x) == MODIFY_EXPR)
- TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
break;
@@ -2994,6 +2992,12 @@ cp_fold (tree x)
return org_x;
}
+ if (EXPR_P (x) && TREE_CODE (x) == code)
+ {
+ TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
+ TREE_NO_WARNING (x) = TREE_NO_WARNING (org_x);
+ }
+
if (!c.evaluation_restricted_p ())
{
fold_cache->put (org_x, x);
diff --git a/gcc/testsuite/c-c++-common/Wparentheses-2.c b/gcc/testsuite/c-c++-common/Wparentheses-2.c
new file mode 100644
index 0000000..1aa5d31
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wparentheses-2.c
@@ -0,0 +1,18 @@
+// PR c++/95344 - bogus -Wparentheses warning.
+// { dg-do compile }
+// { dg-options "-Wparentheses" }
+
+#ifndef __cplusplus
+# define bool _Bool
+# define true 1
+# define false 0
+#endif
+
+void
+f (int i)
+{
+ bool b = false;
+ if (i == 99 ? (b = true) : false) // { dg-bogus "suggest parentheses" }
+ {
+ }
+}