220 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -verify %s2 3// expected-error@+1 {{invalid operands to binary expression ('const char[5]' and 'float')}}4constexpr bool CausesRecoveryExpr = "test" + 1.0f;5 6template<typename T>7concept ReferencesCRE = CausesRecoveryExpr; // #subst18 9template<typename T> requires CausesRecoveryExpr // #NVC1REQ10void NoViableCands1(){} // #NVC111 12template<typename T> requires ReferencesCRE<T> // #NVC2REQ13void NoViableCands2(){} // #NVC214 15template<ReferencesCRE T> // #NVC3REQ16void NoViableCands3(){} // #NVC317 18void 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 36template<typename T> requires CausesRecoveryExpr // #OVC1REQ37void OtherViableCands1(){} // #OVC138 39template<typename T>40void OtherViableCands1(){} // #OVC1_ALT41 42template<typename T> requires ReferencesCRE<T> // #OVC2REQ43void OtherViableCands2(){} // #OVC244 45template<typename T>46void OtherViableCands2(){} // #OVC2_ALT47 48template<ReferencesCRE T> // #OVC3REQ49void OtherViableCands3(){} // #OVC350template<typename T>51void OtherViableCands3(){} // #OVC3_ALT52 53void 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 73template<typename T> requires CausesRecoveryExpr // #OBNVC1REQ74void OtherBadNoViableCands1(){} // #OBNVC175 76template<typename T> requires false // #OBNVC1REQ_ALT77void OtherBadNoViableCands1(){} // #OBNVC1_ALT78 79template<typename T> requires ReferencesCRE<T> // #OBNVC2REQ80void OtherBadNoViableCands2(){} // #OBNVC281 82template<typename T> requires false// #OBNVC2REQ_ALT83void OtherBadNoViableCands2(){} // #OBNVC2_ALT84 85template<ReferencesCRE T> // #OBNVC3REQ86void OtherBadNoViableCands3(){} // #OBNVC387template<typename T> requires false // #OBNVC3REQ_ALT88void OtherBadNoViableCands3(){} // #OBNVC3_ALT89 90void 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.115struct OVC {116template<typename T> requires CausesRecoveryExpr // #MEMOVC1REQ117void OtherViableCands1(){} // #MEMOVC1118 119template<typename T>120void OtherViableCands1(){} // #MEMOVC1_ALT121 122template<typename T> requires ReferencesCRE<T> // #MEMOVC2REQ123void OtherViableCands2(){} // #MEMOVC2124 125template<typename T>126void OtherViableCands2(){} // #MEMOVC2_ALT127 128template<ReferencesCRE T> // #MEMOVC3REQ129void OtherViableCands3(){} // #MEMOVC3130template<typename T>131void OtherViableCands3(){} // #MEMOVC3_ALT132};133 134void 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 155struct StaticOVC {156template<typename T> requires CausesRecoveryExpr // #SMEMOVC1REQ157static void OtherViableCands1(){} // #SMEMOVC1158 159template<typename T>160static void OtherViableCands1(){} // #SMEMOVC1_ALT161 162template<typename T> requires ReferencesCRE<T> // #SMEMOVC2REQ163static void OtherViableCands2(){} // #SMEMOVC2164 165template<typename T>166static void OtherViableCands2(){} // #SMEMOVC2_ALT167 168template<ReferencesCRE T> // #SMEMOVC3REQ169static void OtherViableCands3(){} // #SMEMOVC3170template<typename T>171static void OtherViableCands3(){} // #SMEMOVC3_ALT172};173 174void 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 194namespace GH58548 {195 196template <class, class> struct formatter; // #primary-template197template <class, class> struct basic_format_context {};198 199template <typename CharType>200concept has_format_function =201 format(basic_format_context<CharType, CharType>());202 203template <typename ValueType, typename CharType>204 requires has_format_function<CharType>205struct formatter<ValueType, CharType> {206 template <typename OutputIt>207 CharType format(basic_format_context<OutputIt, CharType>);208};209 210template <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 215int 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} // GH58548220