Zhihao Yuan | 44eee65 | 2022-03-01 19:33:43 -0600 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify |
| 2 | |
| 3 | template <int N> struct Str { |
| 4 | constexpr Str(char const (&s)[N]) { __builtin_memcpy(value, s, N); } |
| 5 | char value[N]; |
| 6 | }; |
| 7 | |
| 8 | template <Str V> class ASCII {}; |
| 9 | |
| 10 | void Foo(ASCII<"this nontype template argument is too long to print">); // expected-note {{no known conversion from 'ASCII<{"this nontype template argument is too long"}>' to 'ASCII<{"this nontype template argument is too long to print"}>'}} |
| 11 | void Bar(ASCII<"this nttp argument is too short">); // expected-note {{no known conversion from 'ASCII<{{119, 97, 105, 116, 32, 97, 32, 115, 27, 99, 111, 110, 100, 0}}>' to 'ASCII<{"this nttp argument is too short"}>'}} |
| 12 | void Meow(ASCII<"what|">); // expected-note {{no known conversion from 'ASCII<{"what??!"}>' to 'ASCII<{"what|"}>' for 1st argument}} |
| 13 | |
| 14 | void test_ascii() { |
| 15 | ASCII<"this nontype template argument" |
| 16 | " is too long"> |
| 17 | a; |
| 18 | Foo(a); // expected-error {{no matching function}} |
Nenad Mikša | 835b99e | 2022-10-28 08:18:38 -0400 | [diff] [blame] | 19 | decltype(a)::display(); // expected-error {{no member named 'display' in 'ASCII<Str<43>{"this nontype template argument is [...]"}>'}} |
Zhihao Yuan | 44eee65 | 2022-03-01 19:33:43 -0600 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | void test_non_ascii() { |
| 23 | ASCII<"wait a s\033cond"> a; |
| 24 | Bar(a); // expected-error {{no matching function}} |
Nenad Mikša | 835b99e | 2022-10-28 08:18:38 -0400 | [diff] [blame] | 25 | decltype(a)::display(); // expected-error {{no member named 'display' in 'ASCII<Str<14>{{119, 97, 105, 116, 32, 97, 32, 115, 27, 99, ...}}>'}} |
Zhihao Yuan | 44eee65 | 2022-03-01 19:33:43 -0600 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | // The dialects (C++20 and above) that accept string literals as non-type |
| 29 | // template arguments do not support trigraphs. |
| 30 | void test_trigraph() { |
| 31 | ASCII<"what??!"> a; // expected-warning {{trigraph ignored}} |
| 32 | Meow(a); // expected-error {{no matching function}} |
Nenad Mikša | 835b99e | 2022-10-28 08:18:38 -0400 | [diff] [blame] | 33 | decltype(a)::display(); // expected-error {{no member named 'display' in 'ASCII<Str<8>{"what??!"}>'}} |
Zhihao Yuan | 44eee65 | 2022-03-01 19:33:43 -0600 | [diff] [blame] | 34 | } |