summaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-04-19 12:12:01 -0400
committerMarek Polacek <polacek@redhat.com>2020-04-20 15:35:06 -0400
commit5bdd4c5d3fc9c143e8edea3b10828e4b75d7a385 (patch)
treea420b94a2c82e22905063b7d211a6de100a4f424 /gcc/cp
parentc5e4be6b3645fb2294296310a3705f8be0e75da8 (diff)
c++: Fix bogus -Wparentheses warning with fold-expression [PR94505]
We issue bogus -Wparentheses warnings (3 of them!) for this fold expression: ((B && true) || ...) Firstly, issuing a warning for a compiler-generated expression is wrong and secondly, B && true must be wrapped in ( ) otherwise you'll get error: binary expression in operand of fold-expression. PR c++/94505 - bogus -Wparentheses warning with fold-expression. * pt.c (fold_expression): Add warning_sentinel for -Wparentheses before calling build_x_binary_op. * g++.dg/cpp1z/fold11.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c1
2 files changed, 7 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 891ec79fcfd..52f199d90bf 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
2020-04-20 Marek Polacek <polacek@redhat.com>
+ PR c++/94505 - bogus -Wparentheses warning with fold-expression.
+ * pt.c (fold_expression): Add warning_sentinel for -Wparentheses
+ before calling build_x_binary_op.
+
+2020-04-20 Marek Polacek <polacek@redhat.com>
+
* coroutines.cc (captures_temporary): Don't assign the result of
STRIP_NOPS to the same variable.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4f4c04e7df8..899df9a330c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -12379,6 +12379,7 @@ fold_expression (tree t, tree left, tree right, tsubst_flags_t complain)
if (FOLD_EXPR_MODIFY_P (t))
return build_x_modify_expr (input_location, left, code, right, complain);
+ warning_sentinel s(warn_parentheses);
switch (code)
{
case COMPOUND_EXPR: