Debian Codegraph @

gcc/testsuite/g++.dg/ext/flexary7.C

raw
1 // PR c++/68613 - initializer-string for array of chars is too long error
2 // on flexible array member
3 // { dg-do compile }
4 // { dg-options "-Wpedantic -Wno-error=pedantic" }
5
6 struct FlexChar {
7 int n;
8 char a[]; // { dg-warning "10:ISO C\\+\\+ forbids flexible array member" }
9 };
10
11 struct FlexChar ac =
12 { 4, { "abc" } }; // { dg-warning "initialization of a flexible array member" }
13
14
15 #if !__cplusplus
16 typedef __WCHAR_TYPE__ wchar_t;
17 #endif
18
19 struct FlexWchar {
20 int n;
21 wchar_t a[]; // { dg-warning "13:ISO C\\+\\+ forbids flexible array member" }
22 };
23
24 struct FlexWchar awc =
25 { 3, { L"ab" } }; // { dg-warning "initialization of a flexible array member" }
26
27
28 struct FlexInt {
29 int n;
30 int a[]; // { dg-warning "9:ISO C\\+\\+ forbids flexible array member" }
31 };
32
33 // Verify that no warning is issued for the case when a flexible array
34 // member is not initialized (i.e., that a -Wmissing-field-initializer
35 // isn't issued) because such arrays need not have any elements.
36 struct FlexInt ai0 =
37 { 0 };
38
39 struct FlexInt ai0_ =
40 { 0, { } }; // { dg-warning "initialization of a flexible array member" }
41
42 struct FlexInt ai2 =
43 { 2, { 1, 2 } }; // { dg-warning "initialization of a flexible array member" }
44
45
46 #if __cplusplus
47
48 template <class T>
49 struct FlexT {
50 int n;
51 T a[]; // { dg-warning "7:ISO C\\+\\+ forbids flexible array member" }
52 };
53
54 struct FlexT<char> atc =
55 { 4, { "abc" } }; // { dg-warning "initialization of a flexible array member" }
56
57 #endif