131
|
1 /* PR tree-optimization/71625 - missing strlen optimization on different
|
|
2 array initialization style
|
|
3
|
|
4 Verify that zero-length array initialization results in the expected
|
|
5 array sizes.
|
|
6
|
|
7 { dg-do compile }
|
|
8 { dg-options "-Wall -Wno-unused-local-typedefs" } */
|
|
9
|
|
10 #define A(expr) typedef char A[-1 + 2 * !!(expr)];
|
|
11
|
|
12 const char a[] = { };
|
|
13
|
|
14 A (sizeof a == 0);
|
|
15
|
|
16
|
|
17 const char b[0] = { };
|
|
18
|
|
19 A (sizeof b == 0);
|
|
20
|
|
21
|
|
22 const char c[0] = { 1 }; /* { dg-warning "excess elements" } */
|
|
23
|
|
24 A (sizeof c == 0);
|
|
25
|
|
26
|
|
27 void test_auto_empty (void)
|
|
28 {
|
|
29 const char a[] = { };
|
|
30
|
|
31 A (sizeof a == 0);
|
|
32 }
|
|
33
|
|
34 void test_auto_zero_length (void)
|
|
35 {
|
|
36 const char a[0] = { };
|
|
37
|
|
38 A (sizeof a == 0);
|
|
39
|
|
40 const char b[0] = { 0 }; /* { dg-warning "excess elements" } */
|
|
41
|
|
42 A (sizeof b == 0);
|
|
43
|
|
44 const char c[0] = "";
|
|
45
|
|
46 A (sizeof c == 0);
|
|
47 }
|
|
48
|
|
49
|
|
50 void test_compound_zero_length (void)
|
|
51 {
|
|
52 A (sizeof (const char[]){ } == 0);
|
|
53 A (sizeof (const char[0]){ } == 0);
|
|
54 A (sizeof (const char[0]){ 0 } == 0); /* { dg-warning "excess elements" } */
|
|
55 A (sizeof (const char[0]){ 1 } == 0); /* { dg-warning "excess elements" } */
|
|
56 A (sizeof (const char[0]){ "" } == 0);
|
|
57 A (sizeof (const char[0]){ "1" } == 0); /* { dg-warning "too long" } */
|
|
58 }
|