| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-Wuninitialized -O2" } */ |
| 3 |
|
| 4 |
/* Multiple initialization paths. */ |
| 5 |
|
| 6 |
typedef long long int64; |
| 7 |
void incr (); |
| 8 |
bool is_valid (int); |
| 9 |
int get_time (); |
| 10 |
|
| 11 |
class A |
| 12 |
{ |
| 13 |
public: |
| 14 |
A (); |
| 15 |
~A () { |
| 16 |
if (I) delete I; |
| 17 |
} |
| 18 |
|
| 19 |
private: |
| 20 |
int* I; |
| 21 |
}; |
| 22 |
|
| 23 |
bool get_url (A *); |
| 24 |
bool get_url2 (A *); |
| 25 |
bool get_url3 (A *); |
| 26 |
|
| 27 |
class M { |
| 28 |
|
| 29 |
public: |
| 30 |
__attribute__ ((always_inline)) |
| 31 |
bool GetC (int *c) { |
| 32 |
|
| 33 |
A details_str; |
| 34 |
|
| 35 |
/* Initialization path 1 */ |
| 36 |
if (get_url (&details_str)) |
| 37 |
{ |
| 38 |
*c = get_time (); |
| 39 |
return true; |
| 40 |
} |
| 41 |
|
| 42 |
/* Destructor call before return*/ |
| 43 |
A tmp_str; |
| 44 |
|
| 45 |
/* Initialization path 2 */ |
| 46 |
if (get_url2 (&details_str)) |
| 47 |
{ |
| 48 |
*c = get_time (); |
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
/* Fail to initialize in this path but |
| 53 |
still returns true */ |
| 54 |
if (get_url2 (&details_str)) |
| 55 |
{ |
| 56 |
/* Fail to initialize *c */ |
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
void do_sth(); |
| 64 |
void do_sth2(); |
| 65 |
|
| 66 |
void P (int64 t) |
| 67 |
{ |
| 68 |
int cc; |
| 69 |
if (!GetC (&cc)) |
| 70 |
return; |
| 71 |
|
| 72 |
if (cc <= 0) /* { dg-warning "uninitialized" "uninitialized variable warning" } */ |
| 73 |
{ |
| 74 |
this->do_sth(); |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
do_sth2(); |
| 79 |
} |
| 80 |
}; |
| 81 |
|
| 82 |
M* m; |
| 83 |
void test(int x) |
| 84 |
{ |
| 85 |
m = new M; |
| 86 |
m->P(x); |
| 87 |
} |