From: Marek Polacek Date: Fri, 24 Mar 2017 14:22:01 +0000 (+0000) Subject: re PR c++/80119 (-Wmaybe-uninitialized wrongly flags the body of a short-circuited... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c8b1fbc12a6a7249f93a985c697c8e0edeb2a6d5;p=gcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 73a25f3f3cc..f8e711b160a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-03-24 Marek Polacek + + 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 PR c++/80150 - ICE with overloaded variadic deduction. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index ebb5da96f0a..354ae1af852 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 886a0f04caf..c0f03ad28dd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-03-24 Marek Polacek + + PR c++/80119 + * g++.dg/warn/Wuninitialized-9.C: New test. + 2017-03-24 Andreas Krebbel * gcc.target/s390/target-attribute/tattr-3.c: Adjust error message diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-9.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-9.C new file mode 100644 index 00000000000..3432b4f337f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wuninitialized-9.C @@ -0,0 +1,19 @@ +// PR c++/80119 +// { dg-do compile { target c++11 } } +// { dg-options "-Wuninitialized" } + +#include + +template +void failing_function(std::integral_constant) +{ + int i; + if (b && (i = 4)) { + ++i; // { dg-bogus "may be used uninitialized" } + } +} + +int main (void) +{ + failing_function(std::false_type()); +}