Commit 5bdd4c5d by Marek Polacek

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.
parent c5e4be6b
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.
......
......@@ -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:
......
2020-04-20 Marek Polacek <polacek@redhat.com>
PR c++/94505 - bogus -Wparentheses warning with fold-expression.
* g++.dg/cpp1z/fold11.C: New test.
2020-04-20 Andreas Krebbel <krebbel@linux.ibm.com>
* g++.dg/pr94666.C: New test.
......
// PR c++/94505 - bogus -Wparentheses warning with fold-expression.
// { dg-do compile { target c++17 } }
// { dg-options "-Wparentheses" }
template <bool... B>
bool foo () {
return ((B && true) || ...); // { dg-bogus "suggest parentheses" }
}
int main () {
foo<true, false, false, true> ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment