re PR c++/80119 (-Wmaybe-uninitialized wrongly flags the body of a short-circuited...
authorMarek Polacek <polacek@redhat.com>
Fri, 24 Mar 2017 14:22:01 +0000 (14:22 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 24 Mar 2017 14:22:01 +0000 (14:22 +0000)
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

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wuninitialized-9.C [new file with mode: 0644]

index 73a25f3f3ccedad95483320bab39b2be281f2efd..f8e711b160a47cefc53f6713ee70f782c27925f1 100644 (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.
index ebb5da96f0abbfab20d13829ba502d9b033e6793..354ae1af852699f4ad35a62abb64f174e2df9ed3 100644 (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;
index 886a0f04cafc6f3e6bd96f24ad9a53e7aaf3aa56..c0f03ad28dd8c0fae896c841bcbd892785fe2b3c 100644 (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
diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-9.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-9.C
new file mode 100644 (file)
index 0000000..3432b4f
--- /dev/null
@@ -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());
+}