// { dg-do compile { target c++20 } } template concept False = false; template concept C1 = __is_same_as(T, int) || __is_same_as(T, long long) || __is_same_as(T, char); template concept IsNotLarge = !__is_same_as(T, long long); template concept IsNotTiny = !__is_same_as(T, char); template struct Foo { static constexpr auto a = [](auto n) { return n; }; template auto b() { return [](False auto n) { return n; }; } }; template struct Bar { static constexpr auto a = [](R t) { return t; }('a'); // { dg-error "no match" } char b = [](R t) { return t; }('b'); // { dg-error "no match" } static constexpr auto a2 = [](char t) requires false { return t; }('a'); // { dg-error "no match" } char b2 = [](char t) requires false { return t; }('b'); // { dg-error "no match" } }; template S c = [](R t) { return t; }('c'); // { dg-error "no match" } template S c2 = [](char t) requires false { return t; }('c'); // { dg-error "no match" } Bar bar; void test0() { auto bar_a = bar.a; auto bar_b = bar.b; auto c = ::c; auto bar_a2 = bar.a2; auto bar_b2 = bar.b2; auto c2 = ::c2; auto g0 = [](T t) { return t; }; auto g1 = [] requires False (T t) { return t; }; auto g2 = [](T t) requires False { return t; }; auto g3 = [](int t) requires False { return t; }; // { dg-error "non-templated" } auto g4 = [](False auto t) { return t; }; auto g5 = [](auto t) requires False { return t; }; auto g6 = [](int t) requires False { return t; }; // { dg-error "non-templated" } auto g7 = [](int t) requires false { return t; }; // { dg-error "non-templated" } g0(0); // { dg-error "no match" } g1(0); // { dg-error "no match" } g2(0); // { dg-error "no match" } g3(0); g4(0); // { dg-error "no match" } g5(0); // { dg-error "no match" } g6(0); g7(0); } void test1() { int var{-1}; auto g0 = [&](T t) { return t; }; auto g1 = [&] requires False (T t) { return t; }; auto g2 = [&](T t) requires False { return t; }; auto g3 = [&](int t) requires False { return t; }; // { dg-error "non-templated" } auto g4 = [&](False auto t) { return t; }; auto g5 = [&](auto t) requires False { return t; }; auto g6 = [&](int t) requires False { return t; }; // { dg-error "non-templated" } auto g7 = [&](int t) requires false { return t; }; // { dg-error "non-templated" } g0(0); // { dg-error "no match" } g1(0); // { dg-error "no match" } g2(0); // { dg-error "no match" } g3(0); g4(0); // { dg-error "no match" } g5(0); // { dg-error "no match" } g6(0); g7(0); } void test2() { auto x = [](auto a, T t, auto b) requires IsNotTiny && IsNotLarge { return a + t + (T)b; }; x(5LL, 2LL, 1); x('0', 2LL, 1LL); // { dg-error "no match" } x(5LL, '0', 1LL); // { dg-error "no match" } x(5LL, 2LL, 1LL); // { dg-error "no match" } } void test3() { auto x = [](IsNotTiny auto a, T t, IsNotLarge auto b) { return a + t + (T)b; }; x(5LL, 2LL, 1); x('0', 2LL, 1LL); // { dg-error "no match" } x(5LL, '0', 1LL); // { dg-error "no match" } x(5LL, 2LL, 1LL); // { dg-error "no match" } } void test4() { auto g = [] requires IsNotTiny(T t) -> T requires IsNotLarge { return t; }; g(5.5); // { dg-error "no match" } g('a'); // { dg-error "no match" } g(1LL); // { dg-error "no match" } } void test5() { Foo foo1; foo1.a(5.5); foo1.a(1LL); foo1.b(); // { dg-error "no match" } foo1.b()(5); // { dg-error "no match" } Foo foo2; foo2.a(5.5); foo2.a(1LL); foo2.b(); // { dg-error "no match" } foo2.b()(5); // { dg-error "no match" } } using Func = int(*)(int); void test6() { Func f1 = [](int a) requires false { return a; }; // { dg-error "non-templated" } Func f2 = [](auto a) requires false { return a; }; // { dg-error "cannot convert" } }