Debian Codegraph @

clang/test/SemaTemplate/concepts-recovery-expr.cpp

raw
1 // RUN: %clang_cc1 -std=c++20 -verify %s
2
3 // expected-error@+1 {{invalid operands to binary expression ('const char[5]' and 'float')}}
4 constexpr bool CausesRecoveryExpr = "test" + 1.0f;
5
6 template<typename T>
7 concept ReferencesCRE = CausesRecoveryExpr; // #subst1
8
9 template<typename T> requires CausesRecoveryExpr // #NVC1REQ
10 void NoViableCands1(){} // #NVC1
11
12 template<typename T> requires ReferencesCRE<T> // #NVC2REQ
13 void NoViableCands2(){} // #NVC2
14
15 template<ReferencesCRE T> // #NVC3REQ
16 void NoViableCands3(){} // #NVC3
17
18 void NVCUse() {
19 NoViableCands1<int>();
20 // expected-error@-1 {{no matching function for call to 'NoViableCands1'}}
21 // expected-note@#NVC1{{candidate template ignored: constraints not satisfied}}
22 // expected-note@#NVC2REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
23 // expected-note@#NVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
24
25 NoViableCands2<int>();
26 // expected-error@-1 {{no matching function for call to 'NoViableCands2'}}
27 // expected-note@#NVC2{{candidate template ignored: constraints not satisfied}}
28 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
29 NoViableCands3<int>();
30 // expected-error@-1 {{no matching function for call to 'NoViableCands3'}}
31 // expected-note@#NVC3{{candidate template ignored: constraints not satisfied}}
32 // expected-note@#NVC3REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
33 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
34 }
35
36 template<typename T> requires CausesRecoveryExpr // #OVC1REQ
37 void OtherViableCands1(){} // #OVC1
38
39 template<typename T>
40 void OtherViableCands1(){} // #OVC1_ALT
41
42 template<typename T> requires ReferencesCRE<T> // #OVC2REQ
43 void OtherViableCands2(){} // #OVC2
44
45 template<typename T>
46 void OtherViableCands2(){} // #OVC2_ALT
47
48 template<ReferencesCRE T> // #OVC3REQ
49 void OtherViableCands3(){} // #OVC3
50 template<typename T>
51 void OtherViableCands3(){} // #OVC3_ALT
52
53 void OVCUse() {
54 OtherViableCands1<int>();
55 // expected-error@-1 {{no matching function for call to 'OtherViableCands1'}}
56 // expected-note@#OVC1_ALT {{candidate function}}
57 // expected-note@#OVC1 {{candidate template ignored: constraints not satisfied}}
58 // expected-note@#OVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
59 OtherViableCands2<int>();
60 // expected-error@-1 {{no matching function for call to 'OtherViableCands2'}}
61 // expected-note@#OVC2_ALT {{candidate function}}
62 // expected-note@#OVC2 {{candidate template ignored: constraints not satisfied}}
63 // expected-note@#OVC2REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
64 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
65 OtherViableCands3<int>();
66 // expected-error@-1 {{no matching function for call to 'OtherViableCands3'}}
67 // expected-note@#OVC3_ALT {{candidate function}}
68 // expected-note@#OVC3 {{candidate template ignored: constraints not satisfied}}
69 // expected-note@#OVC3REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
70 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
71 }
72
73 template<typename T> requires CausesRecoveryExpr // #OBNVC1REQ
74 void OtherBadNoViableCands1(){} // #OBNVC1
75
76 template<typename T> requires false // #OBNVC1REQ_ALT
77 void OtherBadNoViableCands1(){} // #OBNVC1_ALT
78
79 template<typename T> requires ReferencesCRE<T> // #OBNVC2REQ
80 void OtherBadNoViableCands2(){} // #OBNVC2
81
82 template<typename T> requires false// #OBNVC2REQ_ALT
83 void OtherBadNoViableCands2(){} // #OBNVC2_ALT
84
85 template<ReferencesCRE T> // #OBNVC3REQ
86 void OtherBadNoViableCands3(){} // #OBNVC3
87 template<typename T> requires false // #OBNVC3REQ_ALT
88 void OtherBadNoViableCands3(){} // #OBNVC3_ALT
89
90 void OBNVCUse() {
91 OtherBadNoViableCands1<int>();
92 // expected-error@-1 {{no matching function for call to 'OtherBadNoViableCands1'}}
93 // expected-note@#OBNVC1_ALT {{candidate template ignored: constraints not satisfied}}
94 // expected-note@#OBNVC1REQ_ALT {{because 'false' evaluated to false}}
95 // expected-note@#OBNVC1 {{candidate template ignored: constraints not satisfied}}
96 // expected-note@#OBNVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
97 OtherBadNoViableCands2<int>();
98 // expected-error@-1 {{no matching function for call to 'OtherBadNoViableCands2'}}
99 // expected-note@#OBNVC2_ALT {{candidate template ignored: constraints not satisfied}}
100 // expected-note@#OBNVC2REQ_ALT {{because 'false' evaluated to false}}
101 // expected-note@#OBNVC2 {{candidate template ignored: constraints not satisfied}}
102 // expected-note@#OBNVC2REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
103 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
104 OtherBadNoViableCands3<int>();
105 // expected-error@-1 {{no matching function for call to 'OtherBadNoViableCands3'}}
106 // expected-note@#OBNVC3_ALT {{candidate template ignored: constraints not satisfied}}
107 // expected-note@#OBNVC3REQ_ALT {{because 'false' evaluated to false}}
108 // expected-note@#OBNVC3 {{candidate template ignored: constraints not satisfied}}
109 // expected-note@#OBNVC3REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
110 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
111 }
112
113
114 // Same tests with member functions.
115 struct OVC {
116 template<typename T> requires CausesRecoveryExpr // #MEMOVC1REQ
117 void OtherViableCands1(){} // #MEMOVC1
118
119 template<typename T>
120 void OtherViableCands1(){} // #MEMOVC1_ALT
121
122 template<typename T> requires ReferencesCRE<T> // #MEMOVC2REQ
123 void OtherViableCands2(){} // #MEMOVC2
124
125 template<typename T>
126 void OtherViableCands2(){} // #MEMOVC2_ALT
127
128 template<ReferencesCRE T> // #MEMOVC3REQ
129 void OtherViableCands3(){} // #MEMOVC3
130 template<typename T>
131 void OtherViableCands3(){} // #MEMOVC3_ALT
132 };
133
134 void MemOVCUse() {
135 OVC S;
136 S.OtherViableCands1<int>();
137 // expected-error@-1 {{no matching member function for call to 'OtherViableCands1'}}
138 // expected-note@#MEMOVC1_ALT {{candidate function}}
139 // expected-note@#MEMOVC1 {{candidate template ignored: constraints not satisfied}}
140 // expected-note@#MEMOVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
141 S.OtherViableCands2<int>();
142 // expected-error@-1 {{no matching member function for call to 'OtherViableCands2'}}
143 // expected-note@#MEMOVC2_ALT {{candidate function}}
144 // expected-note@#MEMOVC2 {{candidate template ignored: constraints not satisfied}}
145 // expected-note@#MEMOVC2REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
146 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
147 S.OtherViableCands3<int>();
148 // expected-error@-1 {{no matching member function for call to 'OtherViableCands3'}}
149 // expected-note@#MEMOVC3_ALT {{candidate function}}
150 // expected-note@#MEMOVC3 {{candidate template ignored: constraints not satisfied}}
151 // expected-note@#MEMOVC3REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
152 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
153 }
154
155 struct StaticOVC {
156 template<typename T> requires CausesRecoveryExpr // #SMEMOVC1REQ
157 static void OtherViableCands1(){} // #SMEMOVC1
158
159 template<typename T>
160 static void OtherViableCands1(){} // #SMEMOVC1_ALT
161
162 template<typename T> requires ReferencesCRE<T> // #SMEMOVC2REQ
163 static void OtherViableCands2(){} // #SMEMOVC2
164
165 template<typename T>
166 static void OtherViableCands2(){} // #SMEMOVC2_ALT
167
168 template<ReferencesCRE T> // #SMEMOVC3REQ
169 static void OtherViableCands3(){} // #SMEMOVC3
170 template<typename T>
171 static void OtherViableCands3(){} // #SMEMOVC3_ALT
172 };
173
174 void StaticMemOVCUse() {
175 StaticOVC::OtherViableCands1<int>();
176 // expected-error@-1 {{no matching function for call to 'OtherViableCands1'}}
177 // expected-note@#SMEMOVC1_ALT {{candidate function}}
178 // expected-note@#SMEMOVC1 {{candidate template ignored: constraints not satisfied}}
179 // expected-note@#SMEMOVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
180 StaticOVC::OtherViableCands2<int>();
181 // expected-error@-1 {{no matching function for call to 'OtherViableCands2'}}
182 // expected-note@#SMEMOVC2_ALT {{candidate function}}
183 // expected-note@#SMEMOVC2 {{candidate template ignored: constraints not satisfied}}
184 // expected-note@#SMEMOVC2REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
185 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
186 StaticOVC::OtherViableCands3<int>();
187 // expected-error@-1 {{no matching function for call to 'OtherViableCands3'}}
188 // expected-note@#SMEMOVC3_ALT {{candidate function}}
189 // expected-note@#SMEMOVC3 {{candidate template ignored: constraints not satisfied}}
190 // expected-note@#SMEMOVC3REQ{{because 'int' does not satisfy 'ReferencesCRE'}}
191 // expected-note@#subst1{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
192 }
193
194 namespace GH58548 {
195
196 template <class, class> struct formatter; // #primary-template
197 template <class, class> struct basic_format_context {};
198
199 template <typename CharType>
200 concept has_format_function =
201 format(basic_format_context<CharType, CharType>());
202
203 template <typename ValueType, typename CharType>
204 requires has_format_function<CharType>
205 struct formatter<ValueType, CharType> {
206 template <typename OutputIt>
207 CharType format(basic_format_context<OutputIt, CharType>);
208 };
209
210 template <class Ctx> int handle_replacement_field(Ctx arg) {
211 formatter<decltype(arg), int> ctx; // expected-error {{implicit instantiation of undefined template}}
212 return 0;
213 }
214
215 int x = handle_replacement_field(0);
216 // expected-note@-1 {{template specialization 'GH58548::handle_replacement_field<int>' requested here}}
217 // expected-note@#primary-template {{is declared here}}
218
219 } // GH58548