re PR c++/80119 (-Wmaybe-uninitialized wrongly flags the body of a short-circuited if-clause)

PR c++/80119
	* cp-gimplify.c (cp_fold): Strip CLEANUP_POINT_EXPR if the expression
	doesn't have side effects.

	* g++.dg/warn/Wuninitialized-9.C: New test.

From-SVN: r246461
This commit is contained in:
Marek Polacek 2017-03-24 14:22:01 +00:00 committed by Marek Polacek
parent c4d5ab5d09
commit c8b1fbc12a
4 changed files with 38 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2017-03-24 Marek Polacek <polacek@redhat.com>
PR c++/80119
* cp-gimplify.c (cp_fold): Strip CLEANUP_POINT_EXPR if the expression
doesn't have side effects.
2017-03-23 Jason Merrill <jason@redhat.com>
PR c++/80150 - ICE with overloaded variadic deduction.

View File

@ -2056,6 +2056,14 @@ cp_fold (tree x)
code = TREE_CODE (x);
switch (code)
{
case CLEANUP_POINT_EXPR:
/* Strip CLEANUP_POINT_EXPR if the expression doesn't have side
effects. */
r = cp_fold_rvalue (TREE_OPERAND (x, 0));
if (!TREE_SIDE_EFFECTS (r))
x = r;
break;
case SIZEOF_EXPR:
x = fold_sizeof_expr (x);
break;

View File

@ -1,3 +1,8 @@
2017-03-24 Marek Polacek <polacek@redhat.com>
PR c++/80119
* g++.dg/warn/Wuninitialized-9.C: New test.
2017-03-24 Andreas Krebbel <krebbel@linux.vnet.ibm.com>
* gcc.target/s390/target-attribute/tattr-3.c: Adjust error message

View File

@ -0,0 +1,19 @@
// PR c++/80119
// { dg-do compile { target c++11 } }
// { dg-options "-Wuninitialized" }
#include <type_traits>
template <bool b>
void failing_function(std::integral_constant<bool, b>)
{
int i;
if (b && (i = 4)) {
++i; // { dg-bogus "may be used uninitialized" }
}
}
int main (void)
{
failing_function(std::false_type());
}