| 1 |
// PR tree-optimization/80635 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
// { dg-options "-O2 -Wmaybe-uninitialized" } |
| 4 |
|
| 5 |
using size_t = decltype (sizeof (1)); |
| 6 |
inline void *operator new (size_t, void *p) { return p; } |
| 7 |
template<typename T> |
| 8 |
struct optional |
| 9 |
{ |
| 10 |
optional () : m_dummy (), live (false) {} |
| 11 |
void emplace () { new (&m_item) T (); live = true; } |
| 12 |
~optional () { if (live) m_item.~T (); } |
| 13 |
|
| 14 |
union |
| 15 |
{ |
| 16 |
struct {} m_dummy; |
| 17 |
T m_item; |
| 18 |
}; |
| 19 |
bool live; |
| 20 |
}; |
| 21 |
|
| 22 |
extern int get (); |
| 23 |
extern void set (int); |
| 24 |
|
| 25 |
struct A |
| 26 |
{ |
| 27 |
A () : m (get ()) {} |
| 28 |
~A () { set (m); } // { dg-bogus "may be used uninitialized in this function" } |
| 29 |
|
| 30 |
int m; |
| 31 |
}; |
| 32 |
|
| 33 |
struct B |
| 34 |
{ |
| 35 |
B (); |
| 36 |
~B (); |
| 37 |
}; |
| 38 |
|
| 39 |
void func () |
| 40 |
{ |
| 41 |
optional<A> maybe_a; |
| 42 |
optional<B> maybe_b; |
| 43 |
|
| 44 |
maybe_a.emplace (); |
| 45 |
maybe_b.emplace (); |
| 46 |
} |