PR middle-end/55288 - Improve handling/suppression of maybe-uninitialized warnings
authorMartin Sebor <msebor@redhat.com>
Fri, 9 Apr 2021 17:40:48 +0000 (11:40 -0600)
committerMartin Sebor <msebor@redhat.com>
Fri, 9 Apr 2021 17:40:48 +0000 (11:40 -0600)
gcc/testsuite/ChangeLog:
PR middle-end/55288
* g++.dg/warn/uninit-pr55288.C: New test.

gcc/testsuite/g++.dg/warn/uninit-pr55288.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/warn/uninit-pr55288.C b/gcc/testsuite/g++.dg/warn/uninit-pr55288.C
new file mode 100644 (file)
index 0000000..12fbc56
--- /dev/null
@@ -0,0 +1,43 @@
+/* PR tree-optimization/55288 - Improve handling/suppression of
+   maybe-uninitialized warnings
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+struct iterator
+{
+  operator int ();
+  iterator operator++ (int);
+};
+
+void bar (int);
+
+static void foo (int x)
+{
+  bar (x);          // { dg-bogus "uninitialized" }
+}
+
+int baz (iterator j, iterator end, int p)
+{
+  bool valid = false;
+  int q;
+  for (; j != end; j++) {
+    if (p > j) {
+      if (not valid)
+       p = j;
+      break;
+    }
+    else if (p == j) {
+      valid = true;
+      q = -1;
+    }
+    else {
+      valid = true;
+      q = j;
+    }
+  }
+
+  if (valid)
+    foo (q);
+
+  return p;
+}