PR tree-optimization/71625 - missing strlen optimization on different array initializ...
[official-gcc.git] / gcc / testsuite / gcc.dg / init-string-3.c
blobe955f2e6ce13c6e7a8ac86e4e1ef523af0ecb6a0
1 /* PR tree-optimization/71625 - missing strlen optimization on different
2 array initialization style
4 Verify that zero-length array initialization results in the expected
5 array sizes.
7 { dg-do compile }
8 { dg-options "-Wall -Wno-unused-local-typedefs" } */
10 #define A(expr) typedef char A[-1 + 2 * !!(expr)];
12 const char a[] = { };
14 A (sizeof a == 0);
17 const char b[0] = { };
19 A (sizeof b == 0);
22 const char c[0] = { 1 }; /* { dg-warning "excess elements" } */
24 A (sizeof c == 0);
27 void test_auto_empty (void)
29 const char a[] = { };
31 A (sizeof a == 0);
34 void test_auto_zero_length (void)
36 const char a[0] = { };
38 A (sizeof a == 0);
40 const char b[0] = { 0 }; /* { dg-warning "excess elements" } */
42 A (sizeof b == 0);
44 const char c[0] = "";
46 A (sizeof c == 0);
50 void test_compound_zero_length (void)
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" } */