]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add test for bogus warning [PR104076].
authorMartin Sebor <msebor@redhat.com>
Wed, 19 Jan 2022 00:56:20 +0000 (17:56 -0700)
committerMartin Sebor <msebor@redhat.com>
Wed, 19 Jan 2022 01:04:08 +0000 (18:04 -0700)
Related:
PR middle-end/104076 - bogus -Wdangling-pointer on a conditional

gcc/testsuite/ChangeLog:
PR middle-end/104076
* g++.dg/warn/Wdangling-pointer-3.C: New test.

gcc/testsuite/g++.dg/warn/Wdangling-pointer-3.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/warn/Wdangling-pointer-3.C b/gcc/testsuite/g++.dg/warn/Wdangling-pointer-3.C
new file mode 100644 (file)
index 0000000..64117bf
--- /dev/null
@@ -0,0 +1,39 @@
+/* PR middle-end/104076 - bogus -Wdangling-pointer on a conditional expression
+   { dg-do compile { target { c++11 } } }
+   { dg-options "-Wall" } */
+
+namespace std {
+
+template <class T>
+struct initializer_list
+{
+  T *array;
+  __SIZE_TYPE__ nelts;
+
+  initializer_list (const T *a, __SIZE_TYPE__ n)
+    : array (a), nelts (n) { }
+
+  initializer_list()
+  : array (), nelts () { }
+
+  T* begin () const { return array; }
+
+  const T* end () const { return array + nelts; }
+};
+
+}
+
+struct S1
+{
+  S1 (int);
+  ~S1 ();
+};
+
+struct S2 { S2 (std::initializer_list<S1>); };
+
+S2 f1();
+
+S2 f2(bool b)
+{
+  return b ? f1() : S2{0};    // { dg-bogus "-Wdangling-pointer" }
+}