| 1 |
// PR c++/70393 |
| 2 |
// { dg-do run { target c++11 } } |
| 3 |
|
| 4 |
/* 'ab' has a static initializer, but we flubbed the initializer, |
| 5 |
because of B being the primary base. */ |
| 6 |
|
| 7 |
struct A |
| 8 |
{ |
| 9 |
int a = 1; |
| 10 |
}; |
| 11 |
|
| 12 |
struct B |
| 13 |
{ |
| 14 |
B *element = (B*)2; |
| 15 |
|
| 16 |
virtual int vfunc() = 0; |
| 17 |
|
| 18 |
int call_element() |
| 19 |
{ |
| 20 |
return element->vfunc(); |
| 21 |
} |
| 22 |
|
| 23 |
void set_element() |
| 24 |
{ |
| 25 |
element = this; |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
struct AB : public A, public B |
| 30 |
{ |
| 31 |
int vfunc() |
| 32 |
{ |
| 33 |
return 0; |
| 34 |
} |
| 35 |
}; |
| 36 |
|
| 37 |
static AB ab; |
| 38 |
|
| 39 |
int main() |
| 40 |
{ |
| 41 |
if (ab.a != 1) |
| 42 |
return 1; |
| 43 |
if (ab.element != (void*)2) |
| 44 |
return 2; |
| 45 |
|
| 46 |
ab.set_element(); |
| 47 |
return ab.call_element(); |
| 48 |
} |
| 49 |
|