From d1cd4a64f7b706714b9eaf4952e9130c21ba1d7f Mon Sep 17 00:00:00 2001 From: mpolacek Date: Fri, 24 Mar 2017 14:22:01 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@246461 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/cp-gimplify.c | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/Wuninitialized-9.C | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitialized-9.C 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()); +} -- 2.11.4.GIT