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-require-effective-target int32plus } */ 9 /* { dg-options "-std=c99 -pedantic-errors -fshort-enums -fshort-wchar" } */ 10 11 #include <limits.h> 12 #include <stddef.h> 13 14 typedef enum { schar_min = SCHAR_MIN, schar_max = SCHAR_MAX } schar; 15 typedef enum { uchar_max = UCHAR_MAX } uchar; 16 typedef enum { shrt_min = SHRT_MIN, shrt_max = SHRT_MAX } sshrt; 17 typedef enum { ushrt_max = USHRT_MAX } ushrt; 18 19 char a0[] = "foo"; 20 const signed char a2[4] = "foo"; 21 volatile unsigned char a3[3] = "foo"; 22 wchar_t a4[] = L"foo"; 23 const wchar_t a5[3] = L"foo"; 24 volatile ushrt a6[] = L"foo"; 25 26 schar a7[] = "foo"; /* { dg-error "string constant" "a7" } */ 27 uchar a8[] = "foo"; /* { dg-error "string constant" "a8" } */ 28 const schar a9[] = "foo"; /* { dg-error "string constant" "a9" } */ 29 short a10[] = L"foo"; /* { dg-error "string constant" "a10" } */ 30 const sshrt a11[] = L"foo"; /* { dg-error "string constant" "a11" } */ 31 char a12[] = L"foo"; /* { dg-error "from wide string" "a12" } */ 32 wchar_t a13[] = "foo"; /* { dg-error "non-wide string" "a13" } */ 33 34 char b0[] = { "foo" }; 35 const signed char b2[4] = { "foo" }; 36 volatile unsigned char b3[3] = { "foo" }; 37 wchar_t b4[] = { L"foo" }; 38 const wchar_t b5[3] = { L"foo" }; 39 volatile ushrt b6[] = { L"foo" }; 40 41 schar b7[] = { "foo" }; /* { dg-error "string constant" "b7" } */ 42 uchar b8[] = { "foo" }; /* { dg-error "string constant" "b8" } */ 43 const schar b9[] = { "foo" }; /* { dg-error "string constant" "b9" } */ 44 short b10[] = { L"foo" }; /* { dg-error "string constant" "b10" } */ 45 const sshrt b11[] = { L"foo" }; /* { dg-error "string constant" "b11" } */ 46 char b12[] = { L"foo" }; /* { dg-error "from wide string" "b12" } */ 47 wchar_t b13[] = { "foo" }; /* { dg-error "non-wide string" "b13" } */ 48 49 struct s { signed char a[10]; int b; ushrt c[10]; }; 50 51 struct s c = { "foo", 0, L"bar" }; 52 struct s d = { .c = L"bar", .a = "foo" }; 53 54 ushrt *e = (ushrt [7]){ L"bar" }; 55 56 wchar_t f[5][5] = { L"foo", L"bar" }; 57 ushrt g[5][5] = { L"foo", L"bar" }; 58