aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2022-01-18 17:56:20 -0700
committerMartin Sebor <msebor@redhat.com>2022-01-18 18:04:08 -0700
commit6325041c2b68af096195e0eef92091b2e293e950 (patch)
treee9b58caeb76980c1cdc0bfb8d20f6d25f1a52d72 /gcc
parent282110ae8b54250c8dcb73afc6f30761a41e38e6 (diff)
downloadgcc-6325041c2b68af096195e0eef92091b2e293e950.zip
gcc-6325041c2b68af096195e0eef92091b2e293e950.tar.gz
gcc-6325041c2b68af096195e0eef92091b2e293e950.tar.bz2
Add test for bogus warning [PR104076].
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/g++.dg/warn/Wdangling-pointer-3.C39
1 files changed, 39 insertions, 0 deletions
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
index 0000000..64117bf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wdangling-pointer-3.C
@@ -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" }
+}