mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-08 00:01:19 +08:00
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.
This commit is contained in:
parent
c5e4be6b36
commit
5bdd4c5d3f
@ -1,3 +1,9 @@
|
||||
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
|
||||
|
@ -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:
|
||||
|
@ -1,3 +1,8 @@
|
||||
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.
|
||||
|
12
gcc/testsuite/g++.dg/cpp1z/fold11.C
Normal file
12
gcc/testsuite/g++.dg/cpp1z/fold11.C
Normal file
@ -0,0 +1,12 @@
|
||||
// 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> ();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user