Fortran: fix ALLOCATE with SOURCE of deferred character length [PR114019]
[official-gcc.git] / gcc / testsuite / g++.dg / warn / Wplacement-new-size-6.C
blob86a18fa08e63ac5d1bca5d5e6e80f67f09378b34
1 // { dg-do compile }
2 // { dg-options "-Wno-pedantic -Wplacement-new=1" }
4 typedef __typeof__ (sizeof 0) size_t;
6 void* operator new (size_t, void *p) { return p; }
7 void* operator new[] (size_t, void *p) { return p; }
9 struct Ax { char n, a []; };
11 typedef __INT16_TYPE__ Int16;
12 typedef __INT32_TYPE__ Int32;
14 struct BAx { int i; Ax ax; };
16 void fBx1 ()
18   static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ { 3 } } }; // { dg-error "initialization of flexible array member in a nested context" }
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" }
27 void fBx2 ()
29   static BAx bax2 = { 1, /* Ax = */ { 2, /* a[] = */ { 3, 4 } } }; // { dg-error "initialization of flexible array member in a nested context" }
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" }
40 void fBx3 ()
42   static BAx bax2 = { 1, /* Ax = */ { 3, /* a[] = */ { 4, 5, 6 } } }; // { dg-error "initialization of flexible array member in a nested context" }
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" }