uninit var analysis enhancement
[official-gcc.git] / gcc / testsuite / g++.dg / uninit-pred-3_b.C
blobcfe2113bb6e34de5ca1443aa5667f240fd061b7f
1 /* { dg-do compile } */
2 /* { dg-options "-Wuninitialized -O2" } */
4 /* Multiple initialization paths.  */
6 typedef long long int64;
7 void incr ();
8 bool is_valid (int);
9 int  get_time ();
11 class A
13 public:
14   A ();
15   ~A () {
16     if (I) delete I;
17   }
19 private:
20   int* I;
23 bool get_url (A *);
24 bool get_url2 (A *);
25 bool get_url3 (A *);
27 class M {
29  public:
30  __attribute__ ((always_inline))
31  bool GetC (int *c)  {
33     A details_str;
35     /* Initialization path 1  */
36     if (get_url (&details_str))
37       {
38         *c = get_time ();
39         return true;
40       }
42     /* Destructor call before return*/
43     A tmp_str;
45     /* Initialization path 2  */
46     if (get_url2 (&details_str))
47       {
48         *c = get_time ();
49         return true;
50       }
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       }
60     return false;
61   }
63   void do_sth();
64   void do_sth2();
66   void P (int64 t)
67     {
68       int cc; /* { dg-excess-errors "note: 'cc' was declared here" } */
69       if (!GetC (&cc))
70         return;
72       if (cc <= 0)   /* { dg-warning "uninitialized" "uninitialized variable warning" } */
73         {
74           this->do_sth();
75           return;
76         }
78     do_sth2();
79   }
82 M* m;
83 void test(int x)
85   m = new M;
86   m->P(x);