From: Martin Sebor Date: Wed, 19 Jan 2022 00:56:20 +0000 (-0700) Subject: Add test for bogus warning [PR104076]. X-Git-Tag: upstream/12.2.0~1983 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6325041c2b68af096195e0eef92091b2e293e950;p=platform%2Fupstream%2Fgcc.git 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. --- 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 +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); }; + +S2 f1(); + +S2 f2(bool b) +{ + return b ? f1() : S2{0}; // { dg-bogus "-Wdangling-pointer" } +}