comparison gcc/testsuite/g++.dg/ext/flexary12.C @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 1830386684a0
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
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 []; // { dg-error "flexible array member .A::a. in an otherwise empty .struct A." }
10 };
11
12 void f1 ()
13 {
14 // This is the meat of the test from c++/69290:
15 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 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 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 []; // { dg-error "flexible array member .D::a. in an otherwise empty .struct D." }
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 []; // { dg-error "flexible array member" }
56 };
57
58 void f3 ()
59 {
60 struct C<double> cd
61 = { "c" }; // { dg-error "cannot convert .const char\\*. to .double." }
62
63 (void)&cd;
64 }