aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/warn/Warray-bounds-21.C
blob: 57bb98bf63f0a3958a3911b10392f92bc115a9f7 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* PR middle-end/98266 - bogus array subscript is partly outside array
   bounds on virtual inheritance
   Same as Warray-bounds-19.C with nonvirtual inheritance.
   { dg-do compile }
   { dg-options "-O2 -Wall" } */

void* operator new (__SIZE_TYPE__, void *p) { return p; }
void* operator new[] (__SIZE_TYPE__, void *p) { return p; }


struct A
{
  virtual ~A ();
  int ai;
};

struct B: A { };


// Exercise access to base members by ctor of the most derived class.

struct C1: A
{
  int c1i;
  C1 ();
};

struct D1: B, C1
{
  D1 () { B::ai = 0; C1::ai = 1; c1i = 2; };
};

void sink (void*);

void nowarn_derived_ctor_access_decl ()
{
  D1 d1;
  sink (&d1);
}

void nowarn_derived_ctor_access_new ()
{
  D1 *p = new D1;
  sink (p);
}

void nowarn_derived_ctor_access_placement_new ()
{
  char a[sizeof (D1)];
  D1 *p = new (a) D1;
  sink (p);
}

void nowarn_derived_ctor_access_new_array ()
{
  D1 *p = new D1[2];
  sink (p);
}

void nowarn_derived_ctor_access_placement_new_array ()
{
  char a[sizeof (D1) * 2];
  D1 *p = new (a) D1[2];
  sink (p);
}


// Exercise access to base members by ctor of the second most derived class.

struct C2: A
{
  int c2i;
  ~C2 () { ai = 0; c2i = 1; }
};

struct D2: B, C2
{
  D2 ();
};

void nowarn_base_dtor_access_decl ()
{
  D2 d2;
  sink (&d2);
}

void nowarn_base_dtor_access_new ()
{
  D2 *p = new D2;
  sink (p);
}

void nowarn_base_dtor_access_placement_new ()
{
  char a[sizeof (D2)];
  D2 *p = new (a) D2;
  sink (p);
}

void nowarn_base_dtor_access_new_array ()
{
  D2 *p = new D2[2];
  sink (p);
}

void nowarn_base_dtor_access_placement_new_array ()
{
  char a[sizeof (D2) * 2];
  D2 *p = new (a) D2[2];
  sink (p);
}