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