| 1 |
// PR c++/69290 - [6 Regression] g++ ICE on invalid initialization |
| 2 |
// of a flexible array member |
| 3 |
// { dg-do compile } |
| 4 |
|
| 5 |
// Suppress pedantic errors about initialization of a flexible array member. |
| 6 |
// { dg-options "-Wno-pedantic" } |
| 7 |
|
| 8 |
struct A { |
| 9 |
int a []; |
| 10 |
}; |
| 11 |
|
| 12 |
void f1 () |
| 13 |
{ |
| 14 |
// This is the meat of the test from c++/69290: |
| 15 |
static struct A a |
| 16 |
= { "c" }; // { dg-error "invalid conversion from .const char\\*. to .int." } |
| 17 |
|
| 18 |
(void)&a; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
// Exercise other forms of invalid initialization besides the one in the bug. |
| 23 |
struct B { |
| 24 |
int n; |
| 25 |
int a []; |
| 26 |
}; |
| 27 |
|
| 28 |
void f2 () |
| 29 |
{ |
| 30 |
static struct B b1 |
| 31 |
= { 0, "c" }; // { dg-error "invalid conversion from .const char\\*. to .int." } |
| 32 |
|
| 33 |
(void)&b1; |
| 34 |
|
| 35 |
const char s[] = "c"; |
| 36 |
static struct B b2 |
| 37 |
= { 0, s }; // { dg-error "invalid conversion from .const char\\*. to .int." } |
| 38 |
|
| 39 |
(void)&b2; |
| 40 |
} |
| 41 |
|
| 42 |
struct D { |
| 43 |
int a []; |
| 44 |
D (); |
| 45 |
}; |
| 46 |
|
| 47 |
D::D (): // { dg-error "initializer for flexible array member" } |
| 48 |
a ("c") // the initializer also has an invalid type but emitting |
| 49 |
// just the error above is sufficient |
| 50 |
{ } |
| 51 |
|
| 52 |
|
| 53 |
template <class T> |
| 54 |
struct C { |
| 55 |
T a []; |
| 56 |
}; |
| 57 |
|
| 58 |
void f3 () |
| 59 |
{ |
| 60 |
static struct C<double> cd |
| 61 |
= { "c" }; // { dg-error "cannot convert .const char\\*. to .double." } |
| 62 |
|
| 63 |
(void)&cd; |
| 64 |
} |