Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/init/string4.C @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
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 and in the expected diagnostics. See init-string-3.c | |
6 // for the corresponding C test. | |
7 | |
8 // { dg-do compile } | |
9 // { dg-options "-Wall -Wno-unused-local-typedefs -fpermissive" } | |
10 | |
11 #define A(expr) typedef char A[-1 + 2 * !!(expr)]; | |
12 | |
13 const char a[] = { }; | |
14 | |
15 A (sizeof a == 0); | |
16 | |
17 | |
18 const char b[0] = { }; | |
19 | |
20 A (sizeof b == 0); | |
21 | |
22 // Also verify that the error is "too many initializers for | |
23 // 'const char [0]'" and not "initializer-string is too long." | |
24 const char c[0] = { 1 }; // { dg-error "too many initializers for .const char \\\[0]" } | |
25 | |
26 A (sizeof c == 0); | |
27 | |
28 | |
29 void test_auto_empty (void) | |
30 { | |
31 const char a[] = { }; | |
32 | |
33 A (sizeof a == 0); | |
34 } | |
35 | |
36 void test_auto_zero_length (void) | |
37 { | |
38 const char a[0] = { }; | |
39 | |
40 A (sizeof a == 0); | |
41 | |
42 const char b[0] = { 0 }; // { dg-error "too many initializers" } | |
43 | |
44 A (sizeof b == 0); | |
45 | |
46 const char c[0] = ""; // { dg-warning "too long" } | |
47 | |
48 A (sizeof c == 0); | |
49 } | |
50 | |
51 | |
52 void test_compound_zero_length (void) | |
53 { | |
54 A (sizeof (const char[]){ } == 0); | |
55 A (sizeof (const char[0]){ } == 0); | |
56 A (sizeof (const char[0]){ 0 } == 0); // { dg-error "too many" } | |
57 A (sizeof (const char[0]){ 1 } == 0); // { dg-error "too many" } | |
58 A (sizeof (const char[0]){ "" } == 0); // { dg-warning "too long" } | |
59 A (sizeof (const char[0]){ "1" } == 0); // { dg-warning "too long" } | |
60 } |