Debian Codegraph @

gcc/testsuite/gcc.dg/Wunterminated-string-initialization-2.c

raw
1 /* PR c/117178 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wunterminated-string-initialization" } */
4
5 const char a[][4] __attribute__((nonstring)) = {
6 "ABCD",
7 "EFGH",
8 "IJK",
9 "LMNO"
10 };
11 const char b[][2][2] __attribute__((nonstring)) = {
12 { "PQ",
13 "R" },
14 { "S",
15 "TU" }
16 };
17 struct S { int c; char d[3][5] __attribute__((nonstring)); int e; } f = {
18 0,
19 { "abcde",
20 "defg",
21 "hijkl" },
22 1
23 };
24 struct T { int g; char h[3][2][2] __attribute__((nonstring)); int i; } j = {
25 0,
26 { { "m",
27 "no" },
28 { "pq",
29 "r" },
30 { "s",
31 "tu" } },
32 1
33 };
34 const char k[][4] = {
35 "ABCD", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(5 chars into 4 available\\\)" } */
36 "EFGH", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(5 chars into 4 available\\\)" } */
37 "IJK",
38 "LMNO" /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(5 chars into 4 available\\\)" } */
39 };
40 const char l[][2][2] = {
41 { "PQ", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
42 "R" },
43 { "S",
44 "TU" } /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
45 };
46 struct U { int m; char n[3][5]; int o; } p = {
47 0,
48 { "abcde", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(6 chars into 5 available\\\)" } */
49 "defg",
50 "hijkl" }, /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(6 chars into 5 available\\\)" } */
51 1
52 };
53 struct V { int q; char r[3][2][2]; int s; } t = {
54 0,
55 { { "m",
56 "no" }, /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
57 { "pq", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
58 "r" },
59 { "s",
60 "tu" } }, /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
61 1
62 };
63 const char u[][4] __attribute__((nonstring)) = {
64 [3] = "ABCD",
65 [1] = "EFGH",
66 "IJK",
67 [0] = "LMNO"
68 };
69 const char v[][2][2] __attribute__((nonstring)) = {
70 [1][1] = "PQ",
71 [0][1] = "R",
72 [0][0] = "S",
73 [1][0] = "TU"
74 };
75 struct S w = {
76 0,
77 { [2] = "abcde",
78 [0] = "defg",
79 [1] = "hijkl" },
80 1
81 };
82 struct T x = {
83 .i = 0,
84 .h = { [2][1] = "m",
85 [1][1] = "no",
86 [0][0] = "pq" },
87 .h[1][0] = "r",
88 .h[2][0] = "s",
89 .g = 1,
90 .h[0][1] = "tu"
91 };
92 const char y[][4] = {
93 [3] = "ABCD", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(5 chars into 4 available\\\)" } */
94 [1] = "EFGH", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(5 chars into 4 available\\\)" } */
95 "IJK",
96 [0] = "LMNO" /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(5 chars into 4 available\\\)" } */
97 };
98 const char z[][2][2] = {
99 [1][1] = "PQ", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
100 [0][1] = "R",
101 [0][0] = "S",
102 [1][0] = "TU" /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
103 };
104 struct U aa = {
105 0,
106 { [2] = "abcde", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(6 chars into 5 available\\\)" } */
107 [0] = "defg",
108 [1] = "hijkl" }, /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(6 chars into 5 available\\\)" } */
109 1
110 };
111 struct V ab = {
112 .s = 0,
113 .r = { [2][1] = "m",
114 [1][1] = "no", /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
115 [0][0] = "pq" }, /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
116 .r[1][0] = "r",
117 .r[2][0] = "s",
118 .q = 1,
119 .r[0][1] = "tu" /* { dg-warning "initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute \\\(3 chars into 2 available\\\)" } */
120 };