OSDN Git Service

2006-01-05 Erik Edelmann <eedelman@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / init-string-2.c
1 /* Character arrays but not arrays of compatible enum type may be
2    initialized by narrow string literals.  Arrays of type compatible
3    with wchar_t, including compatible enums, may be initialized by
4    wide string literals.  Use -fshort-enums -fshort-wchar so the
5    relevant circumstances can be obtained portably; may still fail if
6    char, short and int do not all have distinct precisions.  */
7 /* { dg-do compile } */
8 /* { dg-options "-std=c99 -pedantic-errors -fshort-enums -fshort-wchar" } */
9
10 #include <limits.h>
11 #include <stddef.h>
12
13 typedef enum { schar_min = SCHAR_MIN, schar_max = SCHAR_MAX } schar;
14 typedef enum { uchar_max = UCHAR_MAX } uchar;
15 typedef enum { shrt_min = SHRT_MIN, shrt_max = SHRT_MAX } sshrt;
16 typedef enum { ushrt_max = USHRT_MAX } ushrt;
17
18 char a0[] = "foo";
19 const signed char a2[4] = "foo";
20 volatile unsigned char a3[3] = "foo";
21 wchar_t a4[] = L"foo";
22 const wchar_t a5[3] = L"foo";
23 volatile ushrt a6[] = L"foo";
24
25 schar a7[] = "foo"; /* { dg-error "string constant" "a7" } */
26 uchar a8[] = "foo"; /* { dg-error "string constant" "a8" } */
27 const schar a9[] = "foo"; /* { dg-error "string constant" "a9" } */
28 short a10[] = L"foo"; /* { dg-error "string constant" "a10" } */
29 const sshrt a11[] = L"foo"; /* { dg-error "string constant" "a11" } */
30 char a12[] = L"foo"; /* { dg-error "from wide string" "a12" } */
31 wchar_t a13[] = "foo"; /* { dg-error "non-wide string" "a13" } */
32
33 char b0[] = { "foo" };
34 const signed char b2[4] = { "foo" };
35 volatile unsigned char b3[3] = { "foo" };
36 wchar_t b4[] = { L"foo" };
37 const wchar_t b5[3] = { L"foo" };
38 volatile ushrt b6[] = { L"foo" };
39
40 schar b7[] = { "foo" }; /* { dg-error "string constant" "b7" } */
41 uchar b8[] = { "foo" }; /* { dg-error "string constant" "b8" } */
42 const schar b9[] = { "foo" }; /* { dg-error "string constant" "b9" } */
43 short b10[] = { L"foo" }; /* { dg-error "string constant" "b10" } */
44 const sshrt b11[] = { L"foo" }; /* { dg-error "string constant" "b11" } */
45 char b12[] = { L"foo" }; /* { dg-error "from wide string" "b12" } */
46 wchar_t b13[] = { "foo" }; /* { dg-error "non-wide string" "b13" } */
47
48 struct s { signed char a[10]; int b; ushrt c[10]; };
49
50 struct s c = { "foo", 0, L"bar" };
51 struct s d = { .c = L"bar", .a = "foo" };
52
53 ushrt *e = (ushrt [7]){ L"bar" };
54
55 wchar_t f[5][5] = { L"foo", L"bar" };
56 ushrt g[5][5] = { L"foo", L"bar" };