| 1 |
/* Test initialization by UTF-8 string literal in C23 with -std=gnu23. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-require-effective-target wchar } */ |
| 4 |
/* { dg-options "-std=gnu23" } */ |
| 5 |
|
| 6 |
typedef __CHAR8_TYPE__ char8_t; |
| 7 |
typedef __CHAR16_TYPE__ char16_t; |
| 8 |
typedef __CHAR32_TYPE__ char32_t; |
| 9 |
typedef __WCHAR_TYPE__ wchar_t; |
| 10 |
|
| 11 |
/* Test that char, signed char, unsigned char, and char8_t arrays can be |
| 12 |
initialized by a UTF-8 string literal. */ |
| 13 |
const char cbuf1[] = u8"text"; |
| 14 |
const char cbuf2[] = { u8"text" }; |
| 15 |
const signed char scbuf1[] = u8"text"; |
| 16 |
const signed char scbuf2[] = { u8"text" }; |
| 17 |
const unsigned char ucbuf1[] = u8"text"; |
| 18 |
const unsigned char ucbuf2[] = { u8"text" }; |
| 19 |
const char8_t c8buf1[] = u8"text"; |
| 20 |
const char8_t c8buf2[] = { u8"text" }; |
| 21 |
|
| 22 |
/* Test that a diagnostic is issued for attempted initialization of |
| 23 |
other character types by a UTF-8 string literal. */ |
| 24 |
const char16_t c16buf1[] = u8"text"; /* { dg-error "from a string literal with type array of .unsigned char." } */ |
| 25 |
const char16_t c16buf2[] = { u8"text" }; /* { dg-error "from a string literal with type array of .unsigned char." } */ |
| 26 |
const char32_t c32buf1[] = u8"text"; /* { dg-error "from a string literal with type array of .unsigned char." } */ |
| 27 |
const char32_t c32buf2[] = { u8"text" }; /* { dg-error "from a string literal with type array of .unsigned char." } */ |
| 28 |
const wchar_t wbuf1[] = u8"text"; /* { dg-error "from a string literal with type array of .unsigned char." } */ |
| 29 |
const wchar_t wbuf2[] = { u8"text" }; /* { dg-error "from a string literal with type array of .unsigned char." } */ |
| 30 |
|
| 31 |
/* Test that char8_t arrays can be initialized by an ordinary string |
| 32 |
literal. */ |
| 33 |
const char8_t c8buf3[] = "text"; |
| 34 |
const char8_t c8buf4[] = { "text" }; |