Debian Codegraph @

gcc/testsuite/g++.dg/cpp26/literals1.C

raw
1 // C++26 P1854R4 - Making non-encodable string literals ill-formed
2 // { dg-do compile { target c++11 } }
3 // { dg-require-effective-target int32 }
4 // { dg-options "-pedantic-errors -finput-charset=UTF-8 -fexec-charset=UTF-8" }
5
6 int a = 'abcd'; // { dg-warning "multi-character character constant" }
7 int b = '\x61\x62\x63\x64'; // { dg-warning "multi-character character constant" }
8 int c = 'รก'; // { dg-error "character not encodable in a single execution character code unit" }
9 int d = '๐Ÿ˜'; // { dg-error "character not encodable in a single execution character code unit" }
10 int e = '\N{FACE WITH TEARS OF JOY}'; // { dg-error "character not encodable in a single execution character code unit" }
11 // { dg-error "named universal character escapes are only valid in" "" { target c++20_down } .-1 }
12 int f = '\U0001F602'; // { dg-error "character not encodable in a single execution character code unit" }
13 wchar_t g = L'abcd'; // { dg-error "multi-character literal cannot have an encoding prefix" "" { target c++23 } }
14 // { dg-warning "multi-character literal cannot have an encoding prefix" "" { target c++20_down } .-1 }
15 wchar_t h = L'\x61\x62\x63\x64'; // { dg-error "multi-character literal cannot have an encoding prefix" "" { target c++23 } }
16 // { dg-warning "multi-character literal cannot have an encoding prefix" "" { target c++20_down } .-1 }
17 wchar_t i = L'รก';
18 char16_t j = u'abcd'; // { dg-error "multi-character literal cannot have an encoding prefix" }
19 char16_t k = u'\x61\x62\x63\x64'; // { dg-error "multi-character literal cannot have an encoding prefix" }
20 char16_t l = u'รก';
21 char16_t m = u'๐Ÿ˜'; // { dg-error "character not encodable in a single code unit" }
22 char16_t n = u'\N{FACE WITH TEARS OF JOY}'; // { dg-error "character not encodable in a single code unit" { target c++23 } }
23 // { dg-error "named universal character escapes are only valid in" "" { target c++20_down } .-1 }
24 char16_t o = u'\U0001F602'; // { dg-error "character not encodable in a single code unit" }
25 char32_t p = U'abcd'; // { dg-error "multi-character literal cannot have an encoding prefix" }
26 char32_t q = U'\x61\x62\x63\x64'; // { dg-error "multi-character literal cannot have an encoding prefix" }
27 char32_t r = U'รก';
28 char32_t s = U'๐Ÿ˜';
29 char32_t t = U'\N{FACE WITH TEARS OF JOY}'; // { dg-error "named universal character escapes are only valid in" "" { target c++20_down } }
30 char32_t u = U'\U0001F602';
31 #if __cpp_unicode_characters >= 201411L
32 auto v = u8'abcd'; // { dg-error "multi-character literal cannot have an encoding prefix" "" { target c++17 } }
33 auto w = u8'\x61\x62\x63\x64'; // { dg-error "multi-character literal cannot have an encoding prefix" "" { target c++17 } }
34 auto x = u8'รก'; // { dg-error "character not encodable in a single code unit" "" { target c++17 } }
35 auto y = u8'๐Ÿ˜'; // { dg-error "character not encodable in a single code unit" "" { target c++17 } }
36 auto z = u8'\N{FACE WITH TEARS OF JOY}'; // { dg-error "character not encodable in a single code unit" "" { target c++17 } }
37 // { dg-error "named universal character escapes are only valid in" "" { target { c++17 && c++20_down } } .-1 }
38 auto aa = u8'\U0001F602'; // { dg-error "character not encodable in a single code unit" "" { target c++17 } }
39 #endif
40 const char *ab = "๐Ÿ˜";
41 const char *ac = "\N{FACE WITH TEARS OF JOY}"; // { dg-error "named universal character escapes are only valid in" "" { target c++20_down } }
42 const char *ad = "\U0001F602";
43 const char16_t *ae = u"๐Ÿ˜";
44 const char16_t *af = u"\N{FACE WITH TEARS OF JOY}"; // { dg-error "named universal character escapes are only valid in" "" { target c++20_down } }
45 const char16_t *ag = u"\U0001F602";
46 const char32_t *ah = U"๐Ÿ˜";
47 const char32_t *ai = U"\N{FACE WITH TEARS OF JOY}"; // { dg-error "named universal character escapes are only valid in" "" { target c++20_down } }
48 const char32_t *aj = U"\U0001F602";
49 auto ak = u8"๐Ÿ˜";
50 auto al = u8"\N{FACE WITH TEARS OF JOY}"; // { dg-error "named universal character escapes are only valid in" "" { target c++20_down } }
51 auto am = u8"\U0001F602";
52 int an = '\x123456789'; // { dg-error "hex escape sequence out of range" }
53 wchar_t ao = L'\x123456789abcdef0'; // { dg-error "hex escape sequence out of range" }
54 char16_t ap = u'\x12345678'; // { dg-error "hex escape sequence out of range" }
55 char32_t aq = U'\x123456789abcdef0'; // { dg-error "hex escape sequence out of range" }
56 #if __cpp_unicode_characters >= 201411L
57 auto ar = u8'\x123456789abcdef0'; // { dg-error "hex escape sequence out of range" "" { target c++17 } }
58 #endif
59 char as = '\xff';
60 #if __SIZEOF_WCHAR_T__ * __CHAR_BIT__ == 32
61 wchar_t at = L'\xffffffff';
62 #elif __SIZEOF_WCHAR_T__ * __CHAR_BIT__ == 16
63 wchar_t at = L'\xffff';
64 #endif
65 int au = '\x1234'; // { dg-error "hex escape sequence out of range" }
66 int av = 'abcdefghijklmnop'; // { dg-warning "multi-character literal with \[0-9]+ characters exceeds 'int' size of \[0-9]+ bytes" }