1661 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -ferror-limit 0 -verify=expected,cxx20 %s2// RUN: %clang_cc1 -std=c++2c -ferror-limit 0 -verify=expected %s3 4namespace PR47043 {5 template<typename T> concept True = true;6 template<typename ...T> concept AllTrue1 = True<T>; // expected-error {{expression contains unexpanded parameter pack 'T'}}7 template<typename ...T> concept AllTrue2 = (True<T> && ...);8 template<typename ...T> concept AllTrue3 = (bool)(True<T> & ...);9 static_assert(AllTrue2<int, float, char>);10 static_assert(AllTrue3<int, float, char>);11}12 13namespace PR47025 {14 template<typename ...T> concept AllAddable1 = requires(T ...t) { (void(t + 1), ...); };15 template<typename ...T> concept AllAddable2 = (requires(T ...t) { (t + 1); } && ...); // expected-error {{requirement contains unexpanded parameter pack 't'}}16 template<typename ...T> concept AllAddable3 = (requires(T t) { (t + 1); } && ...);17 template<typename ...T> concept AllAddable4 = requires(T t) { (t + 1); }; // expected-error {{expression contains unexpanded parameter pack 'T'}}18 template<typename ...T> concept AllAddable5 = requires(T t) { (void(t + 1), ...); }; // expected-error {{does not contain any unexpanded}}19 template<typename ...T> concept AllAddable6 = (requires { (T() + 1); } && ...);20 template<typename ...T> concept AllAddable7 = requires { (T() + 1); }; // expected-error {{expression contains unexpanded parameter pack 'T'}}21 22 static_assert(AllAddable1<int, float>);23 static_assert(AllAddable3<int, float>);24 static_assert(AllAddable6<int, float>);25 static_assert(!AllAddable1<int, void>);26 static_assert(!AllAddable3<int, void>);27 static_assert(!AllAddable6<int, void>);28}29 30namespace PR45699 {31 template<class> concept C = true; // expected-note 2{{here}}32 template<class ...Ts> void f1a() requires C<Ts>; // expected-error {{requires clause contains unexpanded parameter pack 'Ts'}}33 template<class ...Ts> requires C<Ts> void f1b(); // expected-error {{requires clause contains unexpanded parameter pack 'Ts'}}34 template<class ...Ts> void f2a() requires (C<Ts> && ...);35 template<class ...Ts> requires (C<Ts> && ...) void f2b();36 template<class ...Ts> void f3a() requires C<Ts...>; // expected-error {{pack expansion used as argument for non-pack parameter of concept}}37 template<class ...Ts> requires C<Ts...> void f3b(); // expected-error {{pack expansion used as argument for non-pack parameter of concept}}38 template<class ...Ts> void f4() {39 ([] () requires C<Ts> {} ()); // expected-error {{expression contains unexpanded parameter pack 'Ts'}}40 ([]<int = 0> requires C<Ts> () {} ()); // expected-error {{expression contains unexpanded parameter pack 'Ts'}}41 }42 template<class ...Ts> void f5() {43 ([] () requires C<Ts> {} (), ...);44 ([]<int = 0> requires C<Ts> () {} (), ...);45 }46 void g() {47 f1a();48 f1b(); // FIXME: Bad error recovery. expected-error {{undeclared identifier}}49 f2a();50 f2b();51 f3a();52 f3b(); // FIXME: Bad error recovery. expected-error {{undeclared identifier}}53 f4();54 f5();55 }56}57 58namespace P0857R0 {59 template <typename T> static constexpr bool V = true;60 61 void f() {62 auto x = []<bool B> requires B {}; // expected-note {{constraints not satisfied}} expected-note {{false}}63 x.operator()<true>();64 x.operator()<false>(); // expected-error {{no matching member function}}65 66 auto y = []<typename T> requires V<T> () {};67 y.operator()<int>(); // OK68 }69 70 template<typename T> concept C = true;71 template<template<typename T> requires C<T> typename U> struct X {};72 template<typename T> requires C<T> struct Y {};73 X<Y> xy;74}75 76namespace PR50306 {77 template<typename T> concept NotInt = sizeof(T) != sizeof(int); // expected-note {{because}}78 template<typename T> void f() {79 [](NotInt auto) {}(T()); // expected-error {{no matching function}} expected-note {{constraints not satisfied}} expected-note {{because}}80 }81 template void f<char>(); // OK82 template void f<int>(); // expected-note {{in instantiation of}}83}84 85namespace PackInTypeConstraint {86 template<typename T, typename U> concept C = sizeof(T) == sizeof(int); // expected-note 3{{}}87 88 template<typename ...T, C<T> U> void h1(); // expected-error {{type constraint contains unexpanded parameter pack 'T'}}89 template<typename ...T, C<T> ...U> void h2();90 template<typename ...T> void h3(C<T> auto); // expected-error {{type constraint contains unexpanded parameter pack 'T'}}91 template<typename ...T> void h4(C<T> auto...);92 93 template<typename ...T> void f1() {94 []<C<T> U>(U u){}(T()); // expected-error {{unexpanded parameter pack 'T'}}95 }96 template<typename ...T> void f2() {97 ([]<C<T> U>(U u){}(T()), ...); // expected-error {{no match}} expected-note 2{{}}98 }99 template void f2<int, int, int>(); // OK100 template void f2<int, char, double>(); // expected-note {{in instantiation of}}101 void f3() {102 ([]<typename ...T, C<T> U>(U u){}(0), // expected-error {{type constraint contains unexpanded parameter pack 'T'}}103 ...); // expected-error {{does not contain any unexpanded}}104 }105 106 template<typename ...T> void g1() {107 [](C<T> auto){}(T()); // expected-error {{expression contains unexpanded parameter pack 'T'}}108 }109 template<typename ...T> void g2() {110 ([](C<T> auto){}(T()), ...); // expected-error {{no matching function}} expected-note {{constraints not satisfied}} expected-note {{because}}111 }112 template void g2<int, int, int>(); // OK113 template void g2<int, char, double>(); // expected-note {{in instantiation of}}114 void g3() {115 ([]<typename ...T>(C<T> auto){}(1), // expected-error {{type constraint contains unexpanded parameter pack 'T'}}116 ...); // expected-error {{does not contain any unexpanded}}117 }118 119 template<typename ...T> void g4() {120 []() -> C<T> auto{ return T(); }(); // expected-error {{expression contains unexpanded parameter pack 'T'}}121 }122 template<typename ...T> void g5() {123 ([]() -> C<T> auto{ // expected-error-re {{deduced type {{.*}} does not satisfy}} expected-note {{while substituting into a lambda}}124 return T();125 }(), ...);126 }127 template void g5<int, int, int>(); // OK128 template void g5<int, char, double>(); // expected-note {{in instantiation of}}129 void g6() {130 ([]<typename ...T>() -> C<T> auto{ // expected-error {{declaration type contains unexpanded parameter pack 'T'}}131 return T(); // expected-error {{expression contains unexpanded parameter pack 'T'}}132 }(),133 ...); // expected-error {{does not contain any unexpanded}}134 }135}136 137namespace BuiltinIsConstantEvaluated {138 // Check that we do all satisfaction and diagnostic checks in a constant context.139 template<typename T> concept C = __builtin_is_constant_evaluated(); // expected-warning {{always}}140 static_assert(C<int>);141 142 template<typename T> concept D = __builtin_is_constant_evaluated() == true; // expected-warning {{always}}143 static_assert(D<int>);144 145 template<typename T> concept E = __builtin_is_constant_evaluated() == true && // expected-warning {{always}}146 false; // expected-note {{'false' evaluated to false}}147 static_assert(E<int>); // expected-error {{failed}} expected-note {{because 'int' does not satisfy 'E'}}148 149 template<typename T> concept F = __builtin_is_constant_evaluated() == false; // expected-warning {{always}}150 // expected-note@-1 {{'__builtin_is_constant_evaluated() == false' (1 == 0)}}151 static_assert(F<int>); // expected-error {{failed}} expected-note {{because 'int' does not satisfy 'F'}}152 153 template<typename T> concept G = __builtin_is_constant_evaluated() && // expected-warning {{always}}154 false; // expected-note {{'false' evaluated to false}}155 static_assert(G<int>); // expected-error {{failed}} expected-note {{because 'int' does not satisfy 'G'}}156}157 158namespace NoConstantFolding {159 // Ensure we use strict constant evaluation rules when checking satisfaction.160 int n;161 template <class T> concept C = &n + 3 - 3 == &n; // expected-error {{non-constant expression}} expected-note {{cannot refer to element 3 of non-array object}}162 static_assert(C<void>); // expected-note {{while checking}}163}164 165namespace PR50337 {166 template <typename T> concept foo = true;167 template <typename T> concept foo2 = foo<T> && true;168 void f(foo auto, auto);169 void f(foo2 auto, auto);170 void g() { f(1, 2); }171}172 173namespace PR50561 {174 template<typename> concept C = false;175 template<typename T, typename U> void f(T, U);176 template<C T, typename U> void f(T, U) = delete;177 void g() { f(0, 0); }178}179 180namespace PR49188 {181 template<class T> concept C = false; // expected-note 7 {{because 'false' evaluated to false}}182 183 C auto f1() { // expected-error {{deduced type 'void' does not satisfy 'C'}}184 return void();185 }186 C auto f2() { // expected-error {{deduced type 'void' does not satisfy 'C'}}187 return;188 }189 C auto f3() { // expected-error {{deduced type 'void' does not satisfy 'C'}}190 }191 C decltype(auto) f4() { // expected-error {{deduced type 'void' does not satisfy 'C'}}192 return void();193 }194 C decltype(auto) f5() { // expected-error {{deduced type 'void' does not satisfy 'C'}}195 return;196 }197 C decltype(auto) f6() { // expected-error {{deduced type 'void' does not satisfy 'C'}}198 }199 C auto& f7() { // expected-error {{deduced type 'void' does not satisfy 'C'}}200 return void();201 }202 C auto& f8() {203 return; // expected-error {{cannot deduce return type 'C auto &' from omitted return expression}}204 }205 C auto& f9() { // expected-error {{cannot deduce return type 'C auto &' for function with no return statements}}206 }207}208namespace PR53911 {209 template<class T> concept C = false; // expected-note 3 {{because 'false' evaluated to false}}210 211 C auto *f1() { // expected-error {{deduced type 'void' does not satisfy 'C'}}212 return (void*)nullptr;213 }214 C auto *f2() { // expected-error {{deduced type 'int' does not satisfy 'C'}}215 return (int*)nullptr;216 }217 C auto *****f3() { // expected-error {{deduced type 'int' does not satisfy 'C'}}218 return (int*****)nullptr;219 }220}221 222namespace PR54379 {223template <int N>224struct A {225 static void f() requires (N == 0) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}}226 static void f() requires (N == 1) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}}227};228void (*f1)() = A<2>::f; // expected-error {{address of overloaded function 'f' does not match required type}}229 230struct B {231 template <int N2 = 1> static void f() requires (N2 == 0) { return; } // expected-note {{candidate template ignored: constraints not satisfied [with N2 = 1]}} expected-note {{evaluated to false}}232};233void (*f2)() = B::f; // expected-error {{address of overloaded function 'f' does not match required type}}234}235 236namespace PR54443 {237 238template <class T, class U>239struct is_same { static constexpr bool value = false; };240 241template <class T>242struct is_same<T, T> { static constexpr bool value = true; };243 244template <class T, class U>245concept same_as = is_same<T, U>::value; // expected-note-re 4 {{because {{.*}} evaluated to false}}246 247int const &f();248 249same_as<int const> auto i1 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as<const int>'}}250same_as<int const> auto &i2 = f();251same_as<int const> auto &&i3 = f(); // expected-error {{deduced type 'const int &' does not satisfy 'same_as<const int>'}}252 253same_as<int const &> auto i4 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as<const int &>'}}254same_as<int const &> auto &i5 = f(); // expected-error {{deduced type 'const int' does not satisfy 'same_as<const int &>'}}255same_as<int const &> auto &&i6 = f();256 257template <class T>258concept C = false; // expected-note 3 {{because 'false' evaluated to false}}259 260int **const &g();261 262C auto **j1 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}263C auto **&j2 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}264C auto **&&j3 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}265}266 267namespace GH55567 {268template<class, template <class> class> concept C = true;269template <class> struct S {};270void f(C<GH55567::S> auto);271} // namespace GH55567272 273namespace SubConstraintChecks {274template <typename T>275concept TrueConstraint = true;276template <typename T>277concept FalseConstraint = false;278 279template <typename T, typename... Us>280class ContainsConstrainedFuncTrue {281public:282 template <typename V, TrueConstraint Constrained>283 static void func(V &&, Constrained &&C);284};285template <typename T, typename... Us>286class ContainsConstrainedFuncFalse {287public:288 template <typename V, FalseConstraint Constrained>289 static void func(V &&, Constrained &&C);290};291 292template <typename... Us>293concept TrueConstraint2 =294 requires(float &&t) {295 ContainsConstrainedFuncTrue<float, Us...>::func(5, 0.0);296 };297template <typename... Us>298concept FalseConstraint2 =299 requires(float &&t) {300 ContainsConstrainedFuncFalse<float, Us...>::func(5, 0.0); // #FC2_CONSTR301 };302 303template <typename T>304void useTrue(int F)305 requires TrueConstraint2<int>306{}307 308template <typename T>309void useFalse(int F) // #USE_FALSE310 requires FalseConstraint2<int> // #USE_FALSE_CONSTR311{}312 313// Should only diagnose 'false' once instantiated.314void UseUse() {315 useTrue<int>(5);316 useFalse<int>(5);317 // expected-error@-1{{no matching function for call to 'useFalse'}}318 // expected-note@#USE_FALSE{{constraints not satisfied}}319 // expected-note@#USE_FALSE_CONSTR{{because 'int' does not satisfy 'FalseConstraint2'}}320 // expected-note@#FC2_CONSTR {{would be invalid: no matching function for call to 'func'}}321}322} // namespace SubConstraintChecks323 324namespace DeducedTemplateArgs {325template <typename Itr> struct ItrTraits {326 template <typename PtrItr> struct Ptr {327 };328 template <typename PtrItr>329 requires requires { typename PtrItr::pointer; }330 struct Ptr<PtrItr> {331 using type = typename Itr::pointer;332 };333 using pointer = typename Ptr<Itr>::type; // #TRAITS_PTR334};335 336struct complete_itr {337 using pointer = int;338};339 340template <typename T> class Complete {341 using ItrType = ItrTraits<complete_itr>;342 ItrType begin() noexcept { return ItrType(); }343};344 345// This version doesn't have 'pointer', so error confirms we are in the first346// verison of 'Ptr'.347struct not_complete_itr {348};349 350template <typename T> class NotComplete {351 using ItrType = ItrTraits<not_complete_itr>;352 ItrType begin() noexcept { return ItrType(); }353 // expected-error@#TRAITS_PTR{{no type named 'type' in }}354 // expected-note@-2{{in instantiation of template class }}355};356} // namespace DeducedTemplateArgs357 358namespace DeferredInstantiationInstScope {359template <typename T>360struct remove_ref {361 using type = T;362};363template <typename T>364struct remove_ref<T &> {365 using type = T;366};367template <typename T>368struct remove_ref<T &&> {369 using type = T;370};371 372template <typename T>373constexpr bool IsInt = PR54443::is_same<typename remove_ref<T>::type,374 int>::value;375 376template <typename U>377void SingleDepthReferencesTop(U &&u) {378 struct lc {379 void operator()() // #SDRT_OP380 requires IsInt<decltype(u)> // #SDRT_REQ381 {}382 };383 lc lv;384 lv(); // #SDRT_CALL385}386 387template <typename U>388void SingleDepthReferencesTopNotCalled(U &&u) {389 struct lc {390 void operator()()391 requires IsInt<typename decltype(u)::FOO>392 {}393 };394 lc lv;395}396 397template <typename U>398void SingleDepthReferencesTopCalled(U &&u) {399 struct lc {400 void operator()() // #CALLOP401 requires IsInt<typename decltype(u)::FOO> // #CONSTR402 {}403 };404 lc lv;405 lv();406 // expected-error@-1{{no matching function for call to object of type 'lc'}}407 // expected-note@#SDRTC{{in instantiation of function template}}408 // expected-note@#CALLOP{{constraints not satisfied}}409 // expected-note@#CONSTR{{substituted constraint expression is ill-formed}}410}411 412template <typename U>413void SingleDepthReferencesTopLambda(U &&u) {414 []() // #SDRTL_OP415 requires IsInt<decltype(u)> // #SDRTL_REQ416 {}();417}418 419template <typename U>420void DoubleDepthReferencesTop(U &&u) {421 struct lc { // #DDRT_STRCT422 void operator()() {423 struct lc2 {424 void operator()() // #DDRT_OP425 requires IsInt<decltype(u)> // #DDRT_REQ426 {}427 };428 lc2 lv2;429 lv2(); // #DDRT_CALL430 }431 };432 lc lv;433 lv();434}435 436template <typename U>437void DoubleDepthReferencesTopLambda(U &&u) {438 []() { []() // #DDRTL_OP439 requires IsInt<decltype(u)> // #DDRTL_REQ440 {}(); }();441}442 443template <typename U>444void DoubleDepthReferencesAll(U &&u) {445 struct lc { // #DDRA_STRCT446 void operator()(U &&u2) {447 struct lc2 {448 void operator()(U &&u3) // #DDRA_OP449 requires IsInt<decltype(u)> && // #DDRA_REQ450 IsInt<decltype(u2)> && IsInt<decltype(u3)>451 {}452 };453 lc2 lv2;454 lv2(u2); // #DDRA_CALL455 }456 };457 lc lv;458 lv(u);459}460 461template <typename U>462void DoubleDepthReferencesAllLambda(U &&u) {463 [](U &&u2) { // #DDRAL_OP1464 [](U && u3) // #DDRAL_OP2465 requires IsInt<decltype(u)> // #DDRAL_REQ466 && IsInt<decltype(u2)>467 && IsInt<decltype(u3)>468 {}(u2);469 }(u);470}471 472template <typename U>473struct CausesFriendConstraint {474 template <typename V>475 friend void FriendFunc(CausesFriendConstraint, V) // #FF_DECL476 requires IsInt<U> &&477 IsInt<V> // #FF_REQ478 {}479};480// FIXME: Re-enable this test when constraints are allowed to refer to captures.481// template<typename T>482// void ChecksCapture(T x) {483// [y = x]() requires(IsInt<decltype(y)>){}();484// }485 486template <typename T>487void ChecksLocalVar(T x) {488 T Local;489 []() // #CLV_OP490 requires(IsInt<decltype(Local)>) // #CLV_REQ491 {}();492}493 494template <typename T>495void LocalStructMemberVar(T x) {496 struct S {497 T local;498 void foo()499 requires(IsInt<decltype(local)>) // #LSMV_REQ500 {}501 } s;502 s.foo(); // #LSMV_CALL503};504 505template <typename T>506struct ChecksMemberVar {507 T t;508 void foo()509 requires(IsInt<decltype(t)>) // #CMV_FOO510 {}511 template <typename U>512 void foo2() // #CMV_FOO2513 requires(IsInt<decltype(t)>) // #CMV_FOO2_REQ514 {}515};516 517void test_dependent() {518 int v = 0;519 float will_fail;520 SingleDepthReferencesTop(v);521 SingleDepthReferencesTop(will_fail);522 // expected-error@#SDRT_CALL{{no matching function for call to object of type 'lc'}}523 // expected-note@-2{{in instantiation of function template specialization}}524 // expected-note@#SDRT_OP{{candidate function not viable}}525 // expected-note@#SDRT_REQ{{'IsInt<decltype(u)>' evaluated to false}}526 527 SingleDepthReferencesTopNotCalled(v);528 // Won't error unless we try to call it.529 SingleDepthReferencesTopNotCalled(will_fail);530 SingleDepthReferencesTopCalled(v); // #SDRTC531 SingleDepthReferencesTopLambda(v);532 SingleDepthReferencesTopLambda(will_fail);533 // expected-note@-1{{in instantiation of function template specialization}}534 // expected-error@#SDRTL_OP{{no matching function for call to object of type}}535 // expected-note@#SDRTL_OP{{candidate function not viable: constraints not satisfied}}536 // expected-note@#SDRTL_REQ{{because 'IsInt<decltype(u)>' evaluated to false}}537 538 DoubleDepthReferencesTop(v);539 DoubleDepthReferencesTop(will_fail);540 // expected-error@#DDRT_CALL{{no matching function for call to object of type 'lc2'}}541 // expected-note@-2{{in instantiation of function template specialization}}542 // expected-note@#DDRT_STRCT{{in instantiation of member function}}543 // expected-note@#DDRT_OP{{candidate function not viable}}544 // expected-note@#DDRT_REQ{{'IsInt<decltype(u)>' evaluated to false}}545 546 DoubleDepthReferencesTopLambda(v);547 DoubleDepthReferencesTopLambda(will_fail);548 // expected-note@-1{{in instantiation of function template specialization}}549 // expected-error@#DDRTL_OP{{no matching function for call to object of type}}550 // expected-note@#DDRTL_OP{{candidate function not viable: constraints not satisfied}}551 // expected-note@#DDRTL_OP{{while substituting into a lambda expression here}}552 // expected-note@#DDRTL_REQ{{because 'IsInt<decltype(u)>' evaluated to false}}553 DoubleDepthReferencesAll(v);554 DoubleDepthReferencesAll(will_fail);555 // expected-error@#DDRA_CALL{{no matching function for call to object of type 'lc2'}}556 // expected-note@-2{{in instantiation of function template specialization}}557 // expected-note@#DDRA_STRCT{{in instantiation of member function}}558 // expected-note@#DDRA_OP{{candidate function not viable}}559 // expected-note@#DDRA_REQ{{'IsInt<decltype(u)>' evaluated to false}}560 561 DoubleDepthReferencesAllLambda(v);562 DoubleDepthReferencesAllLambda(will_fail);563 // expected-note@-1{{in instantiation of function template specialization}}564 // expected-note@#DDRAL_OP1{{while substituting into a lambda expression here}}565 // expected-error@#DDRAL_OP2{{no matching function for call to object of type}}566 // expected-note@#DDRAL_OP2{{candidate function not viable: constraints not satisfied}}567 // expected-note@#DDRAL_REQ{{because 'IsInt<decltype(u)>' evaluated to false}}568 569 CausesFriendConstraint<int> CFC;570 FriendFunc(CFC, 1);571 FriendFunc(CFC, 1.0);572 // expected-error@-1{{no matching function for call to 'FriendFunc'}}573 // expected-note@#FF_DECL{{constraints not satisfied}}574 // expected-note@#FF_REQ{{because 'IsInt<double>' evaluated to false}}575 576 // FIXME: Re-enable this test when constraints are allowed to refer to captures.577 // ChecksCapture(v);578 579 ChecksLocalVar(v);580 ChecksLocalVar(will_fail);581 // expected-note@-1{{in instantiation of function template specialization}}582 // expected-error@#CLV_OP{{no matching function for call to object of type}}583 // expected-note@#CLV_OP{{candidate function not viable: constraints not satisfied}}584 // expected-note@#CLV_REQ{{because 'IsInt<decltype(Local)>' evaluated to false}}585 586 587 588 LocalStructMemberVar(v);589 LocalStructMemberVar(will_fail);590 // expected-error@#LSMV_CALL{{invalid reference to function 'foo'}}591 // expected-note@-2{{in instantiation of function template specialization}}592 // expected-note@#LSMV_REQ{{because 'IsInt<decltype(this->local)>' evaluated to false}}593 594 ChecksMemberVar<int> CMV;595 CMV.foo();596 CMV.foo2<int>();597 598 ChecksMemberVar<float> CMV2;599 CMV2.foo();600 // expected-error@-1{{invalid reference to function 'foo'}}601 // expected-note@#CMV_FOO{{because 'IsInt<decltype(this->t)>' evaluated to false}}602 CMV2.foo2<float>();603 // expected-error@-1{{no matching member function for call to 'foo2'}}604 // expected-note@#CMV_FOO2{{constraints not satisfied}}605 // expected-note@#CMV_FOO2_REQ{{because 'IsInt<decltype(this->t)>' evaluated to false}}606}607} // namespace DeferredInstantiationInstScope608 609// Ane example of evaluating a concept at two different depths in the same610// evaluation. No diagnostic is expected.611namespace SameConceptDifferentDepth {612template <class _Ip>613concept sentinel_for =614 requires(_Ip __i) {615 __i++;616 };617 618template <class _Ip>619concept bidirectional_iterator =620 sentinel_for<_Ip>;621 622template <class _Iter>623class move_iterator {624public:625 auto operator++(int)626 requires sentinel_for<_Iter>{}627};628 629static_assert(bidirectional_iterator<move_iterator<int>>);630} // namespace SameConceptDifferentDepth631 632namespace VarInit {633template <class _Tp>634concept __can_reference = true;635 636template <class _Iter>637class common_iterator {638public:639 common_iterator() {640 constexpr auto x = requires(_Iter & __i) { { __i } -> __can_reference; };641 }642};643 644void test() {645 auto commonIter1 = common_iterator<int>();646}647} // namespace VarInit648 649 650namespace InlineFriendOperator {651template <typename T>652concept C = true;653template <class _Iter>654class counted_iterator {655 _Iter I;656public:657 constexpr counted_iterator() = default;658 friend constexpr auto operator+( // expected-note {{candidate function not viable}}659 int __n, const counted_iterator &__x)660 requires C<decltype(I)>661 {662 return __x + __n; // expected-error{{invalid operands to binary expression}}663 }664};665 666constexpr bool test() {667 counted_iterator<int> iter;668 auto x = 2 + iter; // expected-note{{in instantiation of member function 'InlineFriendOperator::operator+'}}669 670 return true;671}672} // namespace InlineFriendOperator673 674namespace ClassTemplateInstantiation {675struct Type;676template < typename A, typename B, typename C>677 concept ConstraintF = false; // #ConstraintF678template < typename A, typename B, typename C>679 concept ConstraintT = true;680 681template < typename T > struct Parent {682 template < typename U, ConstraintT<T, U> > struct ChildT{};683 ChildT<Type, Type> CauseInstT;684 template < typename U, ConstraintF<T, U> > struct ChildF{};// #ChildF685 ChildF<Type, Type> CauseInstF; //#CauseInstF686};687 688// expected-error@#CauseInstF{{constraints not satisfied for class template}}689// expected-note@+3{{in instantiation of template class}}690// expected-note@#ChildF{{evaluated to false}}691// expected-note@#ConstraintF{{because 'false' evaluated to false}}692Parent<int> Inst;693} // namespace ClassTemplateInstantiation694 695namespace SelfFriend {696 template<class T>697 concept Constraint = requires (T i) { (*i); };698 template<class T>699 concept Constraint2 = requires (T i) { (*i); };700 701 template<Constraint T>702 struct Iterator {703 template <Constraint>704 friend class Iterator;705 void operator*();706 };707 708 template<Constraint T> // #ITER_BAD709 struct IteratorBad {710 template <Constraint2>//#ITER_BAD_FRIEND711 friend class IteratorBad;712 void operator*();713 };714 715 Iterator<int*> I;716 Iterator<char*> I2;717 IteratorBad<int*> I3; // expected-error@#ITER_BAD_FRIEND{{constraint differs}}718 // expected-note@-1{{in instantiation of template class}}719 // expected-note@#ITER_BAD{{previous template declaration}}720} // namespace SelfFriend721 722 723namespace Surrogates {724int f1(int);725template <auto N>726struct A {727 using F = int(int);728 operator F*() requires N { return f1; } // expected-note{{conversion candidate 'operator int (*)(int)' not viable: constraints not satisfied}}729};730int i = A<true>{}(0);731int j = A<false>{}(0); // expected-error{{no matching function for call to object of type 'A<false>'}}732}733 734 735namespace ConstrainedMemberVarTemplate {736template <long Size> struct Container {737 static constexpr long arity = Size;738 template <typename U>739 requires(sizeof(U) == arity) // #CMVT_REQ740 using var_templ = int;741};742Container<4>::var_templ<int> inst;743Container<5>::var_templ<int> inst_fail;744// expected-error@-1{{constraints not satisfied for alias template 'var_templ'}}745// expected-note@#CMVT_REQ{{because 'sizeof(int) == arity' (4 == 5) evaluated to false}}746} // namespace ConstrainedMemberVarTemplate747 748// These should not diagnose, where we were unintentionally doing so before by749// checking trailing requires clause twice, yet not having the ability to the750// 2nd time, since it was no longer a dependent variant.751namespace InheritedFromPartialSpec {752template<class C>753constexpr bool Check = true;754 755template<typename T>756struct Foo {757 template<typename U>758 Foo(U&&) requires (Check<U>){}759 template<typename U>760 void MemFunc(U&&) requires (Check<U>){}761 template<typename U>762 static void StaticMemFunc(U&&) requires (Check<U>){}763 ~Foo() requires (Check<T>){}764};765 766template<>767 struct Foo<void> : Foo<int> {768 using Foo<int>::Foo;769 using Foo<int>::MemFunc;770 using Foo<int>::StaticMemFunc;771 };772 773void use() {774 Foo<void> F {1.1};775 F.MemFunc(1.1);776 Foo<void>::StaticMemFunc(1.1);777}778 779template<typename T>780struct counted_iterator {781 constexpr auto operator->() const noexcept requires false {782 return T::Invalid;783 };784};785 786template<class _Ip>787concept __has_member_pointer = requires { typename _Ip::pointer; };788 789template<class>790struct __iterator_traits_member_pointer_or_arrow_or_void { using type = void; };791template<__has_member_pointer _Ip>792struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { using type = typename _Ip::pointer; };793 794template<class _Ip>795 requires requires(_Ip& __i) { __i.operator->(); } && (!__has_member_pointer<_Ip>)796struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {797 using type = decltype(declval<_Ip&>().operator->());798};799 800 801void use2() {802 __iterator_traits_member_pointer_or_arrow_or_void<counted_iterator<int>> f;803}804}// namespace InheritedFromPartialSpec805 806namespace GH48182 {807template<typename, typename..., typename = int> // expected-error{{template parameter pack must be the last template parameter}}808concept invalid = true;809 810template<typename> requires invalid<int> // expected-error{{use of undeclared identifier 'invalid'}}811no errors are printed812;813 814static_assert(invalid<int> also here ; // expected-error{{use of undeclared identifier 'invalid'}}815 816int foo() {817 bool b;818 b = invalid<int> not just in declarations; // expected-error{{use of undeclared identifier 'invalid'}}819 return b;820}821} // namespace GH48182822 823namespace GH61777 {824template<class T> concept C = sizeof(T) == 4; // #61777_C825template<class T, class U> concept C2 = sizeof(T) == sizeof(U); //#61777_C2826 827template<class T>828struct Parent {829 template<class, C auto> struct TakesUnary { static const int i = 0 ; }; // #UNARY830 template<class, C2<T> auto> struct TakesBinary { static const int i = 0 ; }; //#BINARY831};832 833static_assert(Parent<void>::TakesUnary<int, 0>::i == 0);834// expected-error@+3{{constraints not satisfied for class template 'TakesUnary'}}835// expected-note@#UNARY{{because 'decltype(0ULL)' (aka 'unsigned long long') does not satisfy 'C'}}836// expected-note@#61777_C{{because 'sizeof(unsigned long long) == 4' (8 == 4) evaluated to false}}837static_assert(Parent<void>::TakesUnary<int, 0uLL>::i == 0);838 839static_assert(Parent<int>::TakesBinary<int, 0>::i == 0);840// expected-error@+3{{constraints not satisfied for class template 'TakesBinary'}}841// expected-note@#BINARY{{because 'C2<decltype(0ULL), int>' evaluated to false}}842// expected-note@#61777_C2{{because 'sizeof(unsigned long long) == sizeof(int)' (8 == 4) evaluated to false}}843static_assert(Parent<int>::TakesBinary<int, 0ULL>::i == 0);844}845 846namespace TemplateInsideNonTemplateClass {847template<typename T, typename U> concept C = true;848 849template<typename T> auto L = []<C<T> U>() {};850 851struct Q {852 template<C<int> U> friend constexpr auto decltype(L<int>)::operator()() const;853};854 855template <class T>856concept C1 = false;857 858struct Foo {859 template <typename>860 struct Bar {};861 862 template <typename T>863 requires(C1<T>)864 struct Bar<T>;865};866 867Foo::Bar<int> BarInstance;868} // namespace TemplateInsideNonTemplateClass869 870namespace GH61959 {871template <typename T0>872concept C = (sizeof(T0) >= 4);873 874template<typename...>875struct Orig { };876 877template<typename T>878struct Orig<T> {879 template<typename> requires C<T>880 void f() { }881 882 template<typename> requires true883 void f() { }884};885 886template <typename...> struct Mod {};887 888template <typename T1, typename T2>889struct Mod<T1, T2> {890 template <typename> requires C<T1>891 constexpr static int f() { return 1; }892 893 template <typename> requires C<T2>894 constexpr static int f() { return 2; }895};896 897static_assert(Mod<int, char>::f<double>() == 1);898static_assert(Mod<char, int>::f<double>() == 2);899 900template<typename T>901struct Outer {902 template<typename ...>903 struct Inner {};904 905 template<typename U>906 struct Inner<U> {907 template<typename V>908 void foo() requires C<U> && C<T> && C<V>{}909 template<typename V>910 void foo() requires true{}911 };912};913 914void bar() {915 Outer<int>::Inner<float> I;916 I.foo<char>();917}918} // namespace GH61959919 920 921namespace TemplateInsideTemplateInsideTemplate {922template<typename T>923concept C1 = false;924 925template <unsigned I0>926struct W0 {927 template <unsigned I1>928 struct W1 {929 template <typename T>930 struct F {931 enum { value = 1 };932 };933 934 template <typename T>935 requires C1<T>936 struct F<T> {937 enum { value = 2 };938 };939 };940};941 942static_assert(W0<0>::W1<1>::F<int>::value == 1);943} // TemplateInsideTemplateInsideTemplate944 945 946namespace GH63181 {947 948template<auto N, class T> void f() {949auto l = []() requires N { }; // expected-note 2{{candidate function not viable: constraints not satisfied}} \950 // expected-note 2{{because 'false' evaluated to false}}951 952l();953// expected-error@-1 {{no matching function for call to object of type}}954void(*ptr)() = l;955// expected-error-re@-1 {{no viable conversion from '(lambda {{.*}})' to 'void (*)()'}}956}957 958template void f<false, int>(); // expected-note {{in instantiation of function template specialization 'GH63181::f<false, int>' requested here}}959template void f<true, int>();960 961template<class T> concept C = __is_same(T, int); // expected-note{{because '__is_same(char, int)' evaluated to false}}962 963template<class... Ts> void f() {964 ([]() requires C<Ts> { return Ts(); }(), ...);965 // expected-error@-1 {{no matching function for call to object of type}} \966 // expected-note@-1 {{candidate function not viable: constraints not satisfied}} \967 // expected-note@-1 {{because 'char' does not satisfy 'C'}}968}969 970template void f<int, int, int>();971template void f<int, int, char>();972//expected-note@-1{{in instantiation of function template specialization 'GH63181::f<int, int, char>' requested here}}973 974 975template <typename T, bool IsTrue>976concept Test = IsTrue; // expected-note 2{{because 'false' evaluated to false}}977 978template <typename T, bool IsTrue>979void params() {980 auto l = [](T t) // expected-note 2{{candidate function not viable: constraints not satisfied}}981 requires Test<decltype(t), IsTrue> // expected-note 2{{because 'Test<decltype(t), false>' evaluated to false}}982 {};983 using F = void(T);984 F* f = l; // expected-error {{no viable conversion from}}985 l(0); // expected-error {{no matching function for call to object}}986}987 988void test_params() {989 params<int, true>();990 params<int, false>(); // expected-note {{in instantiation of function template specialization 'GH63181::params<int, false>' requested here}}991}992 993}994 995namespace GH54678 {996template<class>997concept True = true;998 999template<class>1000concept False = false; // expected-note 9 {{'false' evaluated to false}}1001 1002template<class>1003concept Irrelevant = false;1004 1005template <typename T>1006concept ErrorRequires = requires(ErrorRequires auto x) { x; }; //#GH54678-ill-formed-concept1007// expected-error@-1 {{a concept definition cannot refer to itself}} \1008// expected-error@-1 {{'auto' not allowed in requires expression parameter}} \1009// expected-note@-1 {{declared here}}1010 1011template<typename T> concept C1 = C1<T> && []<C1>(C1 auto) -> C1 auto {};1012//expected-error@-1 4{{a concept definition cannot refer to itself}} \1013//expected-note@-1 4{{declared here}}1014 1015template<class T> void aaa(T t) // expected-note {{candidate template ignored: constraints not satisfied}}1016requires (False<T> || False<T>) || False<T> {} // expected-note 3 {{'int' does not satisfy 'False'}}1017template<class T> void bbb(T t) // expected-note {{candidate template ignored: constraints not satisfied}}1018requires (False<T> || False<T>) && True<T> {} // expected-note 2 {{'long' does not satisfy 'False'}}1019template<class T> void ccc(T t) // expected-note {{candidate template ignored: constraints not satisfied}}1020requires (True<T> || Irrelevant<T>) && False<T> {} // expected-note {{'unsigned long' does not satisfy 'False'}}1021template<class T> void ddd(T t) // expected-note {{candidate template ignored: constraints not satisfied}}1022requires (Irrelevant<T> || True<T>) && False<T> {} // expected-note {{'int' does not satisfy 'False'}}1023template<class T> void eee(T t) // expected-note {{candidate template ignored: constraints not satisfied}}1024requires (Irrelevant<T> || Irrelevant<T> || True<T>) && False<T> {} // expected-note {{'long' does not satisfy 'False'}}1025 1026template<class T> void fff(T t) // expected-note {{candidate template ignored: constraints not satisfied}}1027requires((ErrorRequires<T> || False<T> || True<T>) && False<T>) {} // expected-note {{because 'unsigned long' does not satisfy 'False'}}1028void test() {1029 aaa(42); // expected-error {{no matching function}}1030 bbb(42L); // expected-error{{no matching function}}1031 ccc(42UL); // expected-error {{no matching function}}1032 ddd(42); // expected-error {{no matching function}}1033 eee(42L); // expected-error {{no matching function}}1034 fff(42UL); // expected-error {{no matching function}}1035}1036}1037 1038namespace GH66612 {1039 template<typename C>1040 auto end(C c) ->int; // expected-note {{possible target for call}}1041 1042 template <typename T>1043 concept Iterator = true;1044 1045 template <typename CT>1046 concept Container = requires(CT b) {1047 { end } -> Iterator; // #66612GH_END1048 };1049 1050 static_assert(Container<int>);1051 // expected-error@#66612GH_END{{reference to overloaded function could not be resolved; did you mean to call it?}}1052}1053 1054namespace GH66938 {1055template <class>1056concept True = true;1057 1058template <class>1059concept False = false;1060 1061template <class T>1062void cand(T t)1063 requires False<T> || False<T> || False<T> || False<T> || False<T> ||1064 False<T> || False<T> || False<T> || False<T> || True<T>1065{}1066 1067void test() { cand(42); }1068}1069 1070namespace GH63837 {1071 1072template<class> concept IsFoo = true;1073 1074template<class> struct Struct {1075 template<IsFoo auto... xs>1076 void foo() {}1077 1078 template<auto... xs> requires (... && IsFoo<decltype(xs)>)1079 void bar() {}1080 1081 template<IsFoo auto... xs>1082 static inline int field = 0;1083};1084 1085template void Struct<void>::foo<>();1086template void Struct<void>::bar<>();1087template int Struct<void>::field<1, 2>;1088 1089}1090 1091namespace GH64808 {1092 1093template <class T> struct basic_sender {1094 T func;1095 basic_sender(T) : func(T()) {}1096};1097 1098auto a = basic_sender{[](auto... __captures) {1099 return []() // #note-a-11100 requires((__captures, ...), false) // #note-a-21101 {};1102}()};1103 1104auto b = basic_sender{[](auto... __captures) {1105 return []()1106 requires([](int, double) { return true; }(decltype(__captures)()...))1107 {};1108}(1, 2.33)};1109 1110void foo() {1111 a.func();1112 // expected-error@-1{{no matching function for call}}1113 // expected-note@#note-a-1{{constraints not satisfied}}1114 // expected-note@#note-a-2{{evaluated to false}}1115 b.func();1116}1117 1118} // namespace GH648081119 1120namespace GH86757_1 {1121template <typename...> concept b = false;1122template <typename> concept c = b<>;1123template <typename d> concept f = c< d >;1124template <f> struct e; // expected-note {{}}1125template <f d> struct e<d>; // expected-error {{class template partial specialization is not more specialized than the primary template}}1126}1127 1128 1129namespace constrained_variadic {1130template <typename T = int>1131struct S {1132 void f(); // expected-note {{candidate}}1133 void f(...) requires true; // expected-note {{candidate}}1134 1135 void g(...); // expected-note {{candidate}}1136 void g() requires true; // expected-note {{candidate}}1137 1138 consteval void h(...);1139 consteval void h(...) requires true {};1140};1141 1142int test() {1143 S{}.f(); // expected-error{{call to member function 'f' is ambiguous}}1144 S{}.g(); // expected-error{{call to member function 'g' is ambiguous}}1145 S{}.h();1146}1147 1148}1149 1150namespace GH109780 {1151 1152template <typename T>1153concept Concept; // expected-error {{expected '='}}1154 1155bool val = Concept<int>;1156 1157template <typename T>1158concept C = invalid; // expected-error {{use of undeclared identifier 'invalid'}}1159 1160bool val2 = C<int>;1161 1162} // namespace GH1097801163 1164namespace GH121980 {1165 1166template <class>1167concept has_member_difference_type; // expected-error {{expected '='}}1168 1169template <has_member_difference_type> struct incrementable_traits; // expected-note {{declared here}}1170 1171template <has_member_difference_type Tp>1172struct incrementable_traits<Tp>; // expected-error {{not more specialized than the primary}}1173 1174}1175 1176namespace InjectedClassNameType {1177 1178template <class, class _Err> class expected {1179public:1180 template <class...>1181 expected(...);1182 1183 template <class _T2, class _E2>1184 friend bool operator==(expected x, expected<_T2, _E2>)1185 requires requires {1186 { x };1187 }1188 {1189 return true;1190 }1191};1192 1193bool test_val_types() {1194 return expected<void, int>() == 1;1195}1196 1197}1198 1199namespace CWG2369_Regression {1200 1201enum class KindEnum {1202 Unknown = 0,1203 Foo = 1,1204};1205 1206template <typename T>1207concept KnownKind = T::kind() != KindEnum::Unknown;1208 1209template <KnownKind T> struct KnownType;1210 1211struct Type {1212 KindEnum kind() const;1213 1214 static Type f(Type t);1215 1216 template <KnownKind T> static KnownType<T> f(T t);1217 1218 static void g() {1219 Type t;1220 f(t);1221 }1222};1223 1224template <KnownKind T> struct KnownType {1225 static constexpr KindEnum kind() { return KindEnum::Foo; }1226};1227 1228}1229 1230namespace CWG2369_Regression_2 {1231 1232template <typename T>1233concept HasFastPropertyForAttribute =1234 requires(T element, int name) { element.propertyForAttribute(name); };1235 1236template <typename OwnerType>1237struct SVGPropertyOwnerRegistry {1238 static int fastAnimatedPropertyLookup() {1239 static_assert (HasFastPropertyForAttribute<OwnerType>);1240 return 1;1241 }1242};1243 1244class SVGCircleElement {1245 friend SVGPropertyOwnerRegistry<SVGCircleElement>;1246 void propertyForAttribute(int);1247};1248 1249int i = SVGPropertyOwnerRegistry<SVGCircleElement>::fastAnimatedPropertyLookup();1250 1251}1252 1253namespace GH61824 {1254 1255template<typename T, typename U = typename T::type> // #T_Type1256concept C = true;1257 1258constexpr bool f(C auto) { // #GH61824_f1259 return true;1260}1261 1262C auto x = 0;1263// expected-error@#T_Type {{type 'int' cannot be used prior to '::'}} \1264// expected-note@-1 {{in instantiation of default argument}}1265 1266static_assert(f(0));1267 1268}1269 1270namespace GH149986 {1271template <typename T> concept PerfectSquare = [](){} // expected-note 2{{here}}1272([](auto) { return true; }) < PerfectSquare <class T>;1273// expected-error@-1 {{declaration of 'T' shadows template parameter}} \1274// expected-error@-1 {{a concept definition cannot refer to itself}}1275 1276}1277namespace GH61811{1278template <class T> struct A { static const int x = 42; };1279template <class Ta> concept A42 = A<Ta>::x == 42;1280template <class Tv> concept Void = __is_same_as(Tv, void);1281template <class Tb, class Ub> concept A42b = Void<Tb> || A42<Ub>;1282template <class Tc> concept R42c = A42b<Tc, Tc&>;1283static_assert (R42c<void>);1284}1285 1286namespace parameter_mapping_regressions {1287 1288namespace case1 {1289 1290template <template <class> class> using __meval = struct __q;1291template <template <class> class _Tp>1292concept __mvalid = requires { typename __meval<_Tp>; };1293template <class _Fn>1294concept __minvocable = __mvalid<_Fn::template __f>;1295template <class...> struct __mdefer_;1296template <class _Fn, class... _Args>1297 requires __minvocable<_Fn>1298struct __mdefer_<_Fn, _Args...> {};1299template <class = __q> struct __mtransform {1300 template <class> using __f = int;1301};1302struct __completion_domain_or_none_ : __mdefer_<__mtransform<>> {};1303 1304}1305 1306namespace case2 {1307 1308template<auto& Q, class P> concept C = Q.template operator()<P>();1309template<class P> concept E = C<[]<class Ty>{ return false; }, P>;1310static_assert(!E<int>);1311 1312}1313 1314 1315namespace case3 {1316template <class> constexpr bool is_move_constructible_v = false;1317 1318template <class _Tp>1319concept __cpp17_move_constructible = is_move_constructible_v<_Tp>; // #is_move_constructible_v1320 1321template <class _Tp>1322concept __cpp17_copy_constructible = __cpp17_move_constructible<_Tp>; // #__cpp17_move_constructible1323 1324template <class _Iter>1325concept __cpp17_iterator = __cpp17_copy_constructible<_Iter>; // #__cpp17_copy_constructible1326 1327struct not_move_constructible {};1328static_assert(__cpp17_iterator<not_move_constructible>); \1329// expected-error {{static assertion failed}} \1330// expected-note {{because 'not_move_constructible' does not satisfy '__cpp17_iterator'}} \1331// expected-note@#__cpp17_copy_constructible {{because 'not_move_constructible' does not satisfy '__cpp17_copy_constructible'}} \1332// expected-note@#__cpp17_move_constructible {{because 'parameter_mapping_regressions::case3::not_move_constructible' does not satisfy '__cpp17_move_constructible'}} \1333// expected-note@#is_move_constructible_v {{because 'is_move_constructible_v<parameter_mapping_regressions::case3::not_move_constructible>' evaluated to false}}1334}1335 1336namespace case4 {1337 1338template<bool b>1339concept bool_ = b;1340 1341template<typename... Ts>1342concept unary = bool_<sizeof...(Ts) == 1>;1343 1344static_assert(!unary<>);1345static_assert(unary<void>);1346 1347}1348 1349namespace case5 {1350 1351template<int size>1352concept true1 = size == size;1353 1354template<typename... Ts>1355concept true2 = true1<sizeof...(Ts)>;1356 1357template<typename... Ts>1358concept true3 = true2<Ts...>;1359 1360static_assert(true3<void>);1361 1362}1363 1364namespace case6 {1365 1366namespace std {1367template <int __v>1368struct integral_constant {1369 static const int value = __v;1370};1371 1372template <class _Tp, class... _Args>1373constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);1374 1375template <class _From, class _To>1376constexpr bool is_convertible_v = __is_convertible(_From, _To);1377 1378template <class>1379struct tuple_size;1380 1381template <class _Tp>1382constexpr decltype(sizeof(int)) tuple_size_v = tuple_size<_Tp>::value;1383} // namespace std1384 1385template <int N, int X>1386concept FixedExtentConstructibleFromExtent = X == N;1387 1388template <int Extent>1389struct span {1390 int static constexpr extent = Extent;1391 template <typename R, int N = std::tuple_size_v<R>>1392 requires(FixedExtentConstructibleFromExtent<extent, N>)1393 span(R);1394};1395 1396template <class, int>1397struct array {};1398 1399template <class _Tp, decltype(sizeof(int)) _Size>1400struct std::tuple_size<array<_Tp, _Size>> : integral_constant<_Size> {};1401 1402static_assert(std::is_convertible_v<array<int, 3>, span<3>>);1403static_assert(!std::is_constructible_v<span<4>, array<int, 3>>);1404 1405}1406 1407namespace case7 {1408 1409template <class _Tp, class _Up>1410concept __same_as_impl = __is_same(_Tp, _Up);1411template <class _Tp, class _Up>1412concept same_as = __same_as_impl<_Tp, _Up>;1413template <typename>1414concept IsEntitySpec =1415 requires { requires same_as<void, void>; };1416 1417}1418 1419namespace case8 {1420 1421template <class T>1422struct type_identity {1423 using type = T;1424};1425 1426template <typename Inner>1427struct Cat {};1428 1429template <typename T>1430concept CatConcept = requires {1431 []<class Inner>(type_identity<Cat<Inner>>) {}(type_identity<T>{});1432};1433 1434template <typename Dummy>1435struct Feeder {1436 template <CatConcept Dummy2>1437 void feed() noexcept {}1438};1439 1440void main() { Feeder<int>{}.feed<Cat<int>>(); }1441 1442}1443 1444namespace case9 {1445 1446template <typename>1447concept a = requires { requires true; };1448template <typename T>1449concept b = a<typename T::EntitySpec>;1450template <typename T>1451concept c = requires { b<T>; };1452template <typename T>1453 requires c<T>1454struct s;1455template <typename> constexpr bool f() { return true; }1456template <typename T> constexpr bool d = f<T>();1457struct s2;1458static_assert(d<s<s2>>);1459 1460}1461 1462}1463 1464namespace GH162125 {1465template<typename, int size>1466concept true_int = (size, true);1467 1468template<typename, typename... Ts>1469concept true_types = true_int<void, sizeof...(Ts)>;1470 1471template<typename, typename... Ts>1472concept true_types2 = true_int<void, Ts...[0]{1}>; // cxx20-warning {{pack indexing is a C++2c extension}}1473 1474template<typename... Ts>1475struct s {1476 template<typename T> requires true_types<T, Ts...> && true_types2<T, Ts...>1477 static void f(T);1478};1479void(*test)(int) = &s<bool>::f<int>;1480}1481 1482namespace GH162125_reversed {1483template<int size, typename>1484concept true_int = (size, true);1485 1486template<typename, typename... Ts>1487concept true_types = true_int<sizeof...(Ts), void>;1488 1489template<typename, typename... Ts>1490concept true_types2 = true_int<Ts...[0]{1}, void>; // cxx20-warning {{pack indexing is a C++2c extension}}1491 1492template<typename... Ts>1493struct s {1494 template<typename T> requires true_types<T, Ts...> && true_types2<T, Ts...>1495 static void f(T);1496};1497 1498void(*test)(int) = &s<bool>::f<int>;1499}1500namespace GH51246 {1501void f(); // expected-note {{possible target for call}}1502void f(int); // expected-note {{possible target for call}}1503void g();1504static_assert(requires { f; }); // expected-error {{reference to overloaded function could not be resolved}}1505static_assert(requires { g; });1506struct S {1507 void mf() {1508 static_assert(requires { mf(); });1509 static_assert(requires { mf; }); // expected-error {{reference to non-static member function must be called}}1510 static_assert(requires { S::mf; }); // expected-error {{reference to non-static member function must be called}}1511 }1512 void mf2(int); // expected-note 2{{possible target for call}}1513 void mf2() { // expected-note 2{{possible target for call}}1514 static_assert(requires { mf2; }); // expected-error {{reference to non-static member function must be called}}1515 static_assert(requires { S::mf2; }); // expected-error {{reference to non-static member function must be called}}1516 }1517};1518 1519} // namespace GH512461520 1521 1522namespace GH97753 {1523 1524void f(); // expected-note {{possible target for call}}1525void f(int); // expected-note {{possible target for call}}1526 1527template<typename T>1528concept C = sizeof(T) == 42;1529 1530static_assert( requires {{ &f } -> C;} ); // expected-error {{reference to overloaded function could not be resolved;}}1531// expected-error@-1 {{static assertion failed due to requirement 'requires { { &f() } -> C; }'}}1532 1533}1534 1535namespace GH162092 {1536 1537template <typename T>1538struct vector;1539 1540template <typename T, typename U>1541concept C = __is_same_as(T, U);1542 1543template<class T, auto Cpt>1544concept generic_range_value = requires {1545 Cpt.template operator()<int>();1546};1547 1548 1549template<generic_range_value<[]<1550 C<int>1551 >() {}> T>1552void x() {}1553 1554void foo() {1555 x<vector<int>>();1556}1557 1558}1559 1560namespace GH162770 {1561 enum e {};1562 template<e> struct s {};1563 1564 template<typename> struct specialized;1565 template<e x> struct specialized<s<x>> {1566 static auto make(auto) -> s<x>;1567 };1568 1569 template<e x> struct check {1570 static constexpr auto m = requires { specialized<s<x>>::make(0); };1571 };1572 1573 template<typename... Ts> auto comma = (..., Ts());1574 auto b = comma<check<e{}>>;1575} // namespace GH1627701576 1577namespace GH164750 {1578 1579template <typename>1580struct a;1581template <typename>1582struct b;1583 1584template <template <typename> typename c, typename d, typename>1585concept e = !__is_convertible_to(c<d>*, b<d>*);1586 1587template <typename...>1588struct f;1589template <typename g, typename... h>1590struct f<g, h...> {1591 g i;1592};1593 1594template <typename, typename>1595struct u;1596template <typename j, template <typename> typename k, typename l>1597 requires e<k, j, l>1598struct u<const k<j>*, l> {1599 u(const a<j>*);1600};1601template <typename j, template <typename> typename k, typename l>1602struct u<const k<j>*, l> {1603 u(const b<j>*);1604};1605 1606template <typename>1607struct m;1608template <typename n, typename... o>1609struct m<n (*)(o...)> {1610 template <template <typename> typename j>1611 using p = j<o...>;1612};1613 1614template <typename q, typename r>1615struct s {1616 template <typename... p>1617 struct D {1618 using v = f<u<r, p>...>;1619 };1620 template <typename... t>1621 s(t... p1) : x(p1...) {}1622 m<q>::template p<D>::v x;1623};1624template <typename w, typename... t>1625void fn1(w, t... p2) {1626 s<w, t...>(p2...);1627}1628int* fn2(int) { return nullptr; }1629void fn3() {1630 fn1(fn2, static_cast<const a<int>*>(nullptr));1631 fn1(fn2, static_cast<const b<int>*>(nullptr));1632}1633 1634}1635 1636namespace GH165238 {1637 1638namespace std {1639template <typename, typename _Tp>1640concept output_iterator = requires(_Tp __t) { __t; };1641template <typename _Out> struct basic_format_context {1642 static_assert(output_iterator<_Out, int>);1643 using char_type = _Out;1644};1645template <typename> class basic_format_parse_context;1646template <typename, typename _Context, typename _Formatter,1647 typename = basic_format_parse_context<typename _Context::char_type>>1648concept __parsable_with = requires(_Formatter __f) { __f; };1649template <typename _Tp, typename _CharT,1650 typename _Context = basic_format_context<_CharT>>1651concept __formattable_impl = __parsable_with<_Tp, _Context, _Context>;1652template <typename _Tp, typename _CharT>1653concept formattable = __formattable_impl<_Tp, _CharT>;1654} // namespace std1655struct {1656 void operator()(std::formattable<char> auto);1657} call;1658void foo() { call(""); }1659 1660}1661