Debian Codegraph @

clang/test/SemaTemplate/instantiate-template-argument.cpp

raw
1 // RUN: %clang_cc1 -std=c++2a -x c++ %s -verify=expected,cxx20
2 // RUN: %clang_cc1 -std=c++2c -x c++ %s -verify
3
4
5 template<auto T, decltype(T) U>
6 concept C1 = sizeof(U) >= 4;
7 // sizeof(U) >= 4 [U = U (decltype(T))]
8
9 template<typename Y, char V>
10 concept C2 = C1<Y{}, V>;
11 // sizeof(U) >= 4 [U = V (decltype(Y{}))]
12
13 template<char W>
14 constexpr int foo() requires C2<int, W> { return 1; } // #cand1
15 // sizeof(U) >= 4 [U = W (decltype(int{}))]
16
17 template<char X>
18 constexpr int foo() requires C1<1, X> && true { return 2; } // #cand2
19 // sizeof(U) >= 4 [U = X (decltype(1))]
20
21 static_assert(foo<'a'>() == 2);
22
23
24 template<char Z>
25 constexpr int foo() requires C2<long long, Z> && true { return 3; } // #cand3
26 // sizeof(U) >= 4 [U = Z (decltype(long long{}))]
27
28 static_assert(foo<'a'>() == 3);
29 // expected-error@-1{{call to 'foo' is ambiguous}}
30 // expected-note@#cand2 {{candidate function}}
31 // expected-note@#cand3 {{candidate function}}
32
33
34 namespace case1 {
35
36 template<auto T, decltype(T) U>
37 concept C1 = sizeof(T) >= 4; // #case1_C1
38
39 template<typename Y, char V>
40 concept C2 = C1<Y{}, V>; // #case1_C2
41
42 template<class T, char W>
43 constexpr int foo() requires C2<T, W> { return 1; } // #case1_foo1
44
45 template<class T, char X>
46 constexpr int foo() requires C1<T{}, X> && true { return 2; } // #case1_foo2
47
48 static_assert(foo<char, 'a'>() == 2);
49 // expected-error@-1{{no matching function for call to 'foo'}}
50 // expected-note@#case1_foo1{{candidate template ignored: constraints not satisfied [with T = char, W = 'a']}}
51 // expected-note@#case1_foo1{{because 'C2<char, 'a'>' evaluated to false}}
52 // expected-note@#case1_C2{{because 'C1<char{}, 'a'>' evaluated to false}}
53 // expected-note@#case1_C1{{because 'sizeof ('\x00') >= 4' (1 >= 4) evaluated to false}}
54 // expected-note@#case1_foo2{{candidate template ignored: constraints not satisfied [with T = char, X = 'a']}}
55 // expected-note@#case1_foo2{{because 'C1<char{}, 'a'>' evaluated to false}}
56 // expected-note@#case1_C1{{because 'sizeof ('\x00') >= 4' (1 >= 4) evaluated to false}}
57
58 static_assert(foo<int, 'a'>() == 2);
59
60 }
61
62 namespace packs {
63
64 template<auto T, decltype(T) U>
65 concept C1 = sizeof(U) >= 4;
66
67 template<typename Y, char V>
68 concept C2 = C1<Y{}, V>;
69
70 template<char... W>
71 constexpr int foo() requires (C2<int, W> && ...) { return 1; } // #packs-cand1
72
73 template<char... X>
74 constexpr int foo() requires (C1<1, X> && ...) && true { return 2; } // #packs-cand2
75
76 static_assert(foo<'a'>() == 2);
77 // cxx20-error@-1{{call to 'foo' is ambiguous}}
78 // cxx20-note@#packs-cand1 {{candidate function}}
79 // cxx20-note@#packs-cand2 {{candidate function}}
80
81 }
82
83 namespace case2 {
84 template<auto T> concept C1 = sizeof(decltype(T)) >= 0;
85 template<typename Y> concept C2 = C1<Y{}>;
86
87 template<char W>
88 constexpr int foo() requires C2<int> { return 1; }
89
90 template<char X>
91 constexpr int foo() requires C1<0> && true { return 2; }
92
93 static_assert(foo<0>() == 2);
94 }
95
96 namespace case3 {
97 template<auto T> concept C1 = sizeof(decltype(T)) >= 0;
98
99 template<typename Y> concept C2 = C1<Y{}>;
100
101 template<char W>
102 constexpr int foo() requires C2<int> { return 1; } // #case3_foo1
103
104 template<char X>
105 constexpr int foo() requires C1<1> && true { return 2; } // #case3_foo2
106
107 static_assert(foo<0>() == 2);
108 // expected-error@-1{{call to 'foo' is ambiguous}}
109 // expected-note@#case3_foo1 {{candidate function}}
110 // expected-note@#case3_foo2 {{candidate function}}
111 }