| 1 |
// { dg-do compile } |
| 2 |
// { dg-options "-Wno-pedantic -Wplacement-new=1" } |
| 3 |
|
| 4 |
typedef __typeof__ (sizeof 0) size_t; |
| 5 |
|
| 6 |
void* operator new (size_t, void *p) { return p; } |
| 7 |
void* operator new[] (size_t, void *p) { return p; } |
| 8 |
|
| 9 |
struct Ax { char n, a []; }; |
| 10 |
|
| 11 |
typedef __INT16_TYPE__ Int16; |
| 12 |
typedef __INT32_TYPE__ Int32; |
| 13 |
|
| 14 |
struct BAx { int i; Ax ax; }; |
| 15 |
|
| 16 |
void fBx1 () |
| 17 |
{ |
| 18 |
static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ { 3 } } }; // { dg-error "initialization of flexible array member in a nested context" } |
| 19 |
|
| 20 |
// The first three bytes of the flexible array member live in the padding. |
| 21 |
new (bax1.ax.a) char; // { dg-warning "placement" "" { target default_packed } } |
| 22 |
new (bax1.ax.a) char[2]; // { dg-warning "placement" "" { target default_packed } } |
| 23 |
new (bax1.ax.a) Int16; // { dg-warning "placement" "" { target default_packed } } |
| 24 |
new (bax1.ax.a) Int32; // { dg-warning "placement" } |
| 25 |
} |
| 26 |
|
| 27 |
void fBx2 () |
| 28 |
{ |
| 29 |
static BAx bax2 = { 1, /* Ax = */ { 2, /* a[] = */ { 3, 4 } } }; // { dg-error "initialization of flexible array member in a nested context" } |
| 30 |
|
| 31 |
// The first three bytes of the flexible array member live in the padding. |
| 32 |
new (bax2.ax.a) char; // { dg-warning "placement" "" { target default_packed } } |
| 33 |
new (bax2.ax.a) char[2]; // { dg-warning "placement" "" { target default_packed } } |
| 34 |
new (bax2.ax.a) char[3]; // { dg-warning "placement" "" { target default_packed } } |
| 35 |
new (bax2.ax.a) Int16; // { dg-warning "placement" "" { target default_packed } } |
| 36 |
new (bax2.ax.a) char[4]; // { dg-warning "placement" } |
| 37 |
new (bax2.ax.a) Int32; // { dg-warning "placement" } |
| 38 |
} |
| 39 |
|
| 40 |
void fBx3 () |
| 41 |
{ |
| 42 |
static BAx bax2 = { 1, /* Ax = */ { 3, /* a[] = */ { 4, 5, 6 } } }; // { dg-error "initialization of flexible array member in a nested context" } |
| 43 |
|
| 44 |
// The first three bytes of the flexible array member live in the padding. |
| 45 |
new (bax2.ax.a) char; // { dg-warning "placement" "" { target default_packed } } |
| 46 |
new (bax2.ax.a) char[2]; // { dg-warning "placement" "" { target default_packed } } |
| 47 |
new (bax2.ax.a) Int16; // { dg-warning "placement" "" { target default_packed } } |
| 48 |
new (bax2.ax.a) char[3]; // { dg-warning "placement" "" { target default_packed } } |
| 49 |
new (bax2.ax.a) char[4]; // { dg-warning "placement" } |
| 50 |
new (bax2.ax.a) Int32; // { dg-warning "placement" } |
| 51 |
} |