aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/flexary12.C
blob: 61726f63f2846ac0383ca74fe8717656193b1292 (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
// PR c++/69290 - [6 Regression] g++ ICE on invalid initialization
//     of a flexible array member
// { dg-do compile }

// Suppress pedantic errors about initialization of a flexible array member.
// { dg-options "-Wno-pedantic" }

struct A {
  int a [];  // { dg-error "flexible array member .A::a. in an otherwise empty .struct A." }
};

void f1 ()
{
  // This is the meat of the test from c++/69290:
  struct A a
    = { "c" };   // { dg-error "invalid conversion from .const char\\*. to .int." }

  (void)&a;
}


// Exercise other forms of invalid initialization besides the one in the bug.
struct B {
  int n;
  int a [];
};

void f2 ()
{
  struct B b1
    = { 0, "c" };   // { dg-error "invalid conversion from .const char\\*. to .int." }

  (void)&b1;

  const char s[] = "c";
  struct B b2
    = { 0, s };   // { dg-error "invalid conversion from .const char\\*. to .int." }

  (void)&b2;
}

struct D {
  int a [];  // { dg-error "flexible array member .D::a. in an otherwise empty .struct D." }
  D ();
};

D::D ():    // { dg-error "initializer for flexible array member" }
  a ("c")   // the initializer also has an invalid type but emitting
	    // just the error above is sufficient
{ }


template <class T>
struct C {
  T a [];  // { dg-error "flexible array member" }
};

void f3 ()
{
  struct C<double> cd
    = { "c" };   // { dg-error "cannot convert .const char\\*. to .double." }

  (void)&cd;
}