[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaTemplate / temp_arg_string_printing.cpp
blob60e89bb09d758d86f5a531363e56aac1beda7745
1 // RUN: %clang_cc1 -std=c++20 -ast-print %s | FileCheck %s
3 using size_t = __SIZE_TYPE__;
4 static_assert(__has_builtin(__make_integer_seq));
6 template <class T, T... I> class idx_seq {};
7 template <size_t N> using make_idx_seq = __make_integer_seq<idx_seq, size_t, N>;
9 template <class CharT, size_t N>
10 struct Str {
11 constexpr Str(CharT const (&s)[N]) : Str(s, make_idx_seq<N>()) {}
12 CharT value[N];
14 private:
15 template <size_t... I>
16 constexpr Str(CharT const (&s)[N], idx_seq<size_t, I...>) : value{s[I]...} {}
19 template <Str> class ASCII {};
21 void not_string() {
22 // CHECK{LITERAL}: ASCII<Str<int, 3>{{9, -1, 42}}>
23 new ASCII<(int[]){9, -1, 42}>;
24 // CHECK{LITERAL}: ASCII<Str<double, 3>{{3.140000e+00, 0.000000e+00, 4.200000e+01}}>
25 new ASCII<(double[]){3.14, 0., 42.}>;
28 void narrow() {
29 // CHECK{LITERAL}: ASCII<Str<char, 1>{""}>
30 new ASCII<"">;
31 // CHECK{LITERAL}: ASCII<Str<char, 26>{"the quick brown fox jumps"}>
32 new ASCII<"the quick brown fox jumps">;
33 // CHECK{LITERAL}: ASCII<Str<char, 29>{"OVER THE LAZY DOG 0123456789"}>
34 new ASCII<"OVER THE LAZY DOG 0123456789">;
35 // CHECK{LITERAL}: ASCII<Str<char, 33>{"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
36 new ASCII<R"(\`~!@#$%^&*()_+-={}[]|'";:,.<>?/)">;
37 // CHECK{LITERAL}: ASCII<Str<char, 8>{{101, 115, 99, 97, 112, 101, 0, 0}}>
38 new ASCII<"escape\0">;
39 // CHECK{LITERAL}: ASCII<Str<char, 9>{"escape\r\n"}>
40 new ASCII<"escape\r\n">;
41 // CHECK{LITERAL}: ASCII<Str<char, 11>{"escape\\\t\f\v"}>
42 new ASCII<"escape\\\t\f\v">;
43 // CHECK{LITERAL}: ASCII<Str<char, 10>{"escape\a\bc"}>
44 new ASCII<"escape\a\b\c">;
45 // CHECK{LITERAL}: ASCII<Str<char, 5>{{110, 111, 116, 17, 0}}>
46 new ASCII<"not\x11">;
47 // CHECK{LITERAL}: ASCII<Str<char, 10>{{18, 20, 127, 16, 1, 32, 97, 98, 99, 0}}>
48 new ASCII<"\x12\x14\x7f\x10\x01 abc">;
49 // CHECK{LITERAL}: ASCII<Str<char, 11>{{18, 20, 127, 16, 1, 32, 97, 98, 99, 100, 0}}>
50 new ASCII<"\x12\x14\x7f\x10\x01 abcd">;
51 // CHECK{LITERAL}: ASCII<Str<char, 32>{"print more characters as string"}>
52 new ASCII<"print more characters as string">;
53 // CHECK{LITERAL}: ASCII<Str<char, 44>{"print more characters as string, no uplimit"}>
54 new ASCII<"print more characters as string, no uplimit">;
57 void wide() {
58 // CHECK{LITERAL}: ASCII<Str<wchar_t, 1>{L""}>
59 new ASCII<L"">;
60 // CHECK{LITERAL}: ASCII<Str<wchar_t, 26>{L"the quick brown fox jumps"}>
61 new ASCII<L"the quick brown fox jumps">;
62 // CHECK{LITERAL}: ASCII<Str<wchar_t, 29>{L"OVER THE LAZY DOG 0123456789"}>
63 new ASCII<L"OVER THE LAZY DOG 0123456789">;
64 // CHECK{LITERAL}: ASCII<Str<wchar_t, 33>{L"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
65 new ASCII<LR"(\`~!@#$%^&*()_+-={}[]|'";:,.<>?/)">;
66 // CHECK{LITERAL}: ASCII<Str<wchar_t, 8>{{101, 115, 99, 97, 112, 101, 0, 0}}>
67 new ASCII<L"escape\0">;
68 // CHECK{LITERAL}: ASCII<Str<wchar_t, 9>{L"escape\r\n"}>
69 new ASCII<L"escape\r\n">;
70 // CHECK{LITERAL}: ASCII<Str<wchar_t, 11>{L"escape\\\t\f\v"}>
71 new ASCII<L"escape\\\t\f\v">;
72 // CHECK{LITERAL}: ASCII<Str<wchar_t, 10>{L"escape\a\bc"}>
73 new ASCII<L"escape\a\b\c">;
74 // CHECK{LITERAL}: ASCII<Str<wchar_t, 5>{{110, 111, 116, 17, 0}}>
75 new ASCII<L"not\x11">;
76 // CHECK{LITERAL}: ASCII<Str<wchar_t, 10>{{18, 20, 255, 22909, 136, 32, 97, 98, 99, 0}}>
77 new ASCII<L"\x12\x14\xff\x597d\x88 abc">;
78 // CHECK{LITERAL}: ASCII<Str<wchar_t, 11>{{18, 20, 255, 22909, 136, 32, 97, 98, 99, 100, 0}}>
79 new ASCII<L"\x12\x14\xff\x597d\x88 abcd">;
80 // CHECK{LITERAL}: ASCII<Str<wchar_t, 32>{L"print more characters as string"}>
81 new ASCII<L"print more characters as string">;
82 // CHECK{LITERAL}: ASCII<Str<wchar_t, 44>{L"print more characters as string, no uplimit"}>
83 new ASCII<L"print more characters as string, no uplimit">;
86 void utf8() {
87 // CHECK{LITERAL}: ASCII<Str<char8_t, 1>{u8""}>
88 new ASCII<u8"">;
89 // CHECK{LITERAL}: ASCII<Str<char8_t, 33>{u8"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
90 new ASCII<u8R"(\`~!@#$%^&*()_+-={}[]|'";:,.<>?/)">;
91 // CHECK{LITERAL}: ASCII<Str<char8_t, 8>{{101, 115, 99, 97, 112, 101, 0, 0}}>
92 new ASCII<u8"escape\0">;
93 // CHECK{LITERAL}: ASCII<Str<char8_t, 9>{u8"escape\r\n"}>
94 new ASCII<u8"escape\r\n">;
95 // CHECK{LITERAL}: ASCII<Str<char8_t, 7>{{229, 165, 189, 239, 191, 189, 0}}>
96 new ASCII<u8"\u597d\ufffd">;
97 // CHECK{LITERAL}: ASCII<Str<char8_t, 44>{u8"print more characters as string, no uplimit"}>
98 new ASCII<u8"print more characters as string, no uplimit">;
101 void utf16() {
102 // CHECK{LITERAL}: ASCII<Str<char16_t, 1>{u""}>
103 new ASCII<u"">;
104 // CHECK{LITERAL}: ASCII<Str<char16_t, 33>{u"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
105 new ASCII<uR"(\`~!@#$%^&*()_+-={}[]|'";:,.<>?/)">;
106 // CHECK{LITERAL}: ASCII<Str<char16_t, 8>{{101, 115, 99, 97, 112, 101, 0, 0}}>
107 new ASCII<u"escape\0">;
108 // CHECK{LITERAL}: ASCII<Str<char16_t, 9>{u"escape\r\n"}>
109 new ASCII<u"escape\r\n">;
110 // CHECK{LITERAL}: ASCII<Str<char16_t, 3>{{22909, 65533, 0}}>
111 new ASCII<u"\u597d\ufffd">;
112 // CHECK{LITERAL}: ASCII<Str<char16_t, 44>{u"print more characters as string, no uplimit"}>
113 new ASCII<u"print more characters as string, no uplimit">;
116 void utf32() {
117 // CHECK{LITERAL}: ASCII<Str<char32_t, 1>{U""}>
118 new ASCII<U"">;
119 // CHECK{LITERAL}: ASCII<Str<char32_t, 33>{U"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
120 new ASCII<UR"(\`~!@#$%^&*()_+-={}[]|'";:,.<>?/)">;
121 // CHECK{LITERAL}: ASCII<Str<char32_t, 8>{{101, 115, 99, 97, 112, 101, 0, 0}}>
122 new ASCII<U"escape\0">;
123 // CHECK{LITERAL}: ASCII<Str<char32_t, 9>{U"escape\r\n"}>
124 new ASCII<U"escape\r\n">;
125 // CHECK{LITERAL}: ASCII<Str<char32_t, 3>{{22909, 131358, 0}}>
126 new ASCII<U"\u597d\U0002011E">;
127 // CHECK{LITERAL}: ASCII<Str<char32_t, 44>{U"print more characters as string, no uplimit"}>
128 new ASCII<U"print more characters as string, no uplimit">;