1 // RUN: %clang_cc1 -std=c++20 -verify %s
3 // expected-error@+1{{use of undeclared identifier 'b'}}
4 constexpr bool CausesRecoveryExpr
= b
;
7 concept ReferencesCRE
= CausesRecoveryExpr
;
9 template<typename T
> requires CausesRecoveryExpr
// #NVC1REQ
10 void NoViableCands1(){} // #NVC1
12 template<typename T
> requires ReferencesCRE
<T
> // #NVC2REQ
13 void NoViableCands2(){} // #NVC2
15 template<ReferencesCRE T
> // #NVC3REQ
16 void NoViableCands3(){} // #NVC3
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@#NVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
24 NoViableCands2
<int>();
25 // expected-error@-1 {{no matching function for call to 'NoViableCands2'}}
26 // expected-note@#NVC2{{candidate template ignored: constraints not satisfied}}
27 // expected-note@#NVC2REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
28 NoViableCands3
<int>();
29 // expected-error@-1 {{no matching function for call to 'NoViableCands3'}}
30 // expected-note@#NVC3{{candidate template ignored: constraints not satisfied}}
31 // expected-note@#NVC3REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
34 template<typename T
> requires CausesRecoveryExpr
// #OVC1REQ
35 void OtherViableCands1(){} // #OVC1
38 void OtherViableCands1(){} // #OVC1_ALT
40 template<typename T
> requires ReferencesCRE
<T
> // #OVC2REQ
41 void OtherViableCands2(){} // #OVC2
44 void OtherViableCands2(){} // #OVC2_ALT
46 template<ReferencesCRE T
> // #OVC3REQ
47 void OtherViableCands3(){} // #OVC3
49 void OtherViableCands3(){} // #OVC3_ALT
52 OtherViableCands1
<int>();
53 // expected-error@-1 {{no matching function for call to 'OtherViableCands1'}}
54 // expected-note@#OVC1_ALT {{candidate function}}
55 // expected-note@#OVC1 {{candidate template ignored: constraints not satisfied}}
56 // expected-note@#OVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
57 OtherViableCands2
<int>();
58 // expected-error@-1 {{no matching function for call to 'OtherViableCands2'}}
59 // expected-note@#OVC2_ALT {{candidate function}}
60 // expected-note@#OVC2 {{candidate template ignored: constraints not satisfied}}
61 // expected-note@#OVC2REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
62 OtherViableCands3
<int>();
63 // expected-error@-1 {{no matching function for call to 'OtherViableCands3'}}
64 // expected-note@#OVC3_ALT {{candidate function}}
65 // expected-note@#OVC3 {{candidate template ignored: constraints not satisfied}}
66 // expected-note@#OVC3REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
69 template<typename T
> requires CausesRecoveryExpr
// #OBNVC1REQ
70 void OtherBadNoViableCands1(){} // #OBNVC1
72 template<typename T
> requires
false // #OBNVC1REQ_ALT
73 void OtherBadNoViableCands1(){} // #OBNVC1_ALT
75 template<typename T
> requires ReferencesCRE
<T
> // #OBNVC2REQ
76 void OtherBadNoViableCands2(){} // #OBNVC2
78 template<typename T
> requires
false// #OBNVC2REQ_ALT
79 void OtherBadNoViableCands2(){} // #OBNVC2_ALT
81 template<ReferencesCRE T
> // #OBNVC3REQ
82 void OtherBadNoViableCands3(){} // #OBNVC3
83 template<typename T
> requires
false // #OBNVC3REQ_ALT
84 void OtherBadNoViableCands3(){} // #OBNVC3_ALT
87 OtherBadNoViableCands1
<int>();
88 // expected-error@-1 {{no matching function for call to 'OtherBadNoViableCands1'}}
89 // expected-note@#OBNVC1_ALT {{candidate template ignored: constraints not satisfied}}
90 // expected-note@#OBNVC1REQ_ALT {{because 'false' evaluated to false}}
91 // expected-note@#OBNVC1 {{candidate template ignored: constraints not satisfied}}
92 // expected-note@#OBNVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
93 OtherBadNoViableCands2
<int>();
94 // expected-error@-1 {{no matching function for call to 'OtherBadNoViableCands2'}}
95 // expected-note@#OBNVC2_ALT {{candidate template ignored: constraints not satisfied}}
96 // expected-note@#OBNVC2REQ_ALT {{because 'false' evaluated to false}}
97 // expected-note@#OBNVC2 {{candidate template ignored: constraints not satisfied}}
98 // expected-note@#OBNVC2REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
99 OtherBadNoViableCands3
<int>();
100 // expected-error@-1 {{no matching function for call to 'OtherBadNoViableCands3'}}
101 // expected-note@#OBNVC3_ALT {{candidate template ignored: constraints not satisfied}}
102 // expected-note@#OBNVC3REQ_ALT {{because 'false' evaluated to false}}
103 // expected-note@#OBNVC3 {{candidate template ignored: constraints not satisfied}}
104 // expected-note@#OBNVC3REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
108 // Same tests with member functions.
110 template<typename T
> requires CausesRecoveryExpr
// #MEMOVC1REQ
111 void OtherViableCands1(){} // #MEMOVC1
114 void OtherViableCands1(){} // #MEMOVC1_ALT
116 template<typename T
> requires ReferencesCRE
<T
> // #MEMOVC2REQ
117 void OtherViableCands2(){} // #MEMOVC2
120 void OtherViableCands2(){} // #MEMOVC2_ALT
122 template<ReferencesCRE T
> // #MEMOVC3REQ
123 void OtherViableCands3(){} // #MEMOVC3
125 void OtherViableCands3(){} // #MEMOVC3_ALT
130 S
.OtherViableCands1
<int>();
131 // expected-error@-1 {{no matching member function for call to 'OtherViableCands1'}}
132 // expected-note@#MEMOVC1_ALT {{candidate function}}
133 // expected-note@#MEMOVC1 {{candidate template ignored: constraints not satisfied}}
134 // expected-note@#MEMOVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
135 S
.OtherViableCands2
<int>();
136 // expected-error@-1 {{no matching member function for call to 'OtherViableCands2'}}
137 // expected-note@#MEMOVC2_ALT {{candidate function}}
138 // expected-note@#MEMOVC2 {{candidate template ignored: constraints not satisfied}}
139 // expected-note@#MEMOVC2REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
140 S
.OtherViableCands3
<int>();
141 // expected-error@-1 {{no matching member function for call to 'OtherViableCands3'}}
142 // expected-note@#MEMOVC3_ALT {{candidate function}}
143 // expected-note@#MEMOVC3 {{candidate template ignored: constraints not satisfied}}
144 // expected-note@#MEMOVC3REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
148 template<typename T
> requires CausesRecoveryExpr
// #SMEMOVC1REQ
149 static void OtherViableCands1(){} // #SMEMOVC1
152 static void OtherViableCands1(){} // #SMEMOVC1_ALT
154 template<typename T
> requires ReferencesCRE
<T
> // #SMEMOVC2REQ
155 static void OtherViableCands2(){} // #SMEMOVC2
158 static void OtherViableCands2(){} // #SMEMOVC2_ALT
160 template<ReferencesCRE T
> // #SMEMOVC3REQ
161 static void OtherViableCands3(){} // #SMEMOVC3
163 static void OtherViableCands3(){} // #SMEMOVC3_ALT
166 void StaticMemOVCUse() {
167 StaticOVC::OtherViableCands1
<int>();
168 // expected-error@-1 {{no matching function for call to 'OtherViableCands1'}}
169 // expected-note@#SMEMOVC1_ALT {{candidate function}}
170 // expected-note@#SMEMOVC1 {{candidate template ignored: constraints not satisfied}}
171 // expected-note@#SMEMOVC1REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
172 StaticOVC::OtherViableCands2
<int>();
173 // expected-error@-1 {{no matching function for call to 'OtherViableCands2'}}
174 // expected-note@#SMEMOVC2_ALT {{candidate function}}
175 // expected-note@#SMEMOVC2 {{candidate template ignored: constraints not satisfied}}
176 // expected-note@#SMEMOVC2REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
177 StaticOVC::OtherViableCands3
<int>();
178 // expected-error@-1 {{no matching function for call to 'OtherViableCands3'}}
179 // expected-note@#SMEMOVC3_ALT {{candidate function}}
180 // expected-note@#SMEMOVC3 {{candidate template ignored: constraints not satisfied}}
181 // expected-note@#SMEMOVC3REQ{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
186 template <class, class> struct formatter
; // #primary-template
187 template <class, class> struct basic_format_context
{};
189 template <typename CharType
>
190 concept has_format_function
=
191 format(basic_format_context
<CharType
, CharType
>());
193 template <typename ValueType
, typename CharType
>
194 requires has_format_function
<CharType
>
195 struct formatter
<ValueType
, CharType
> {
196 template <typename OutputIt
>
197 CharType
format(basic_format_context
<OutputIt
, CharType
>);
200 template <class Ctx
> int handle_replacement_field(Ctx arg
) {
201 formatter
<decltype(arg
), int> ctx
; // expected-error {{implicit instantiation of undefined template}}
205 int x
= handle_replacement_field(0);
206 // expected-note@-1 {{template specialization 'GH58548::handle_replacement_field<int>' requested here}}
207 // expected-note@#primary-template {{is declared here}}