summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/uninit-pred-3_b.C
blob: cfe2113bb6e34de5ca1443aa5667f240fd061b7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* { dg-do compile } */
/* { dg-options "-Wuninitialized -O2" } */

/* Multiple initialization paths.  */

typedef long long int64;
void incr ();
bool is_valid (int);
int  get_time ();

class A
{
public:
  A ();
  ~A () {
    if (I) delete I;
  }

private:
  int* I;
};

bool get_url (A *);
bool get_url2 (A *);
bool get_url3 (A *);

class M {

 public:
 __attribute__ ((always_inline))
 bool GetC (int *c)  {

    A details_str;

    /* Initialization path 1  */
    if (get_url (&details_str))
      {
        *c = get_time ();
        return true;
      }

    /* Destructor call before return*/
    A tmp_str;

    /* Initialization path 2  */
    if (get_url2 (&details_str))
      {
        *c = get_time ();
        return true;
      }

    /* Fail to initialize in this path but
       still returns true  */
    if (get_url2 (&details_str))
      {
        /* Fail to initialize *c  */
        return true;
      }

    return false;
  }

  void do_sth();
  void do_sth2();

  void P (int64 t)
    {
      int cc; /* { dg-excess-errors "note: 'cc' was declared here" } */
      if (!GetC (&cc))
        return;

      if (cc <= 0)   /* { dg-warning "uninitialized" "uninitialized variable warning" } */
        {
          this->do_sth();
          return;
        }

    do_sth2();
  }
};

M* m;
void test(int x)
{
  m = new M;
  m->P(x);
}