1fb943696SRichard Smith // RUN: %clang_cc1 -std=c++20 -verify %s 2fb943696SRichard Smith 3fb943696SRichard Smith namespace PR47043 { 4fb943696SRichard Smith template<typename T> concept True = true; 5fb943696SRichard Smith template<typename ...T> concept AllTrue1 = True<T>; // expected-error {{expression contains unexpanded parameter pack 'T'}} 6fb943696SRichard Smith template<typename ...T> concept AllTrue2 = (True<T> && ...); 7fb943696SRichard Smith static_assert(AllTrue2<int, float, char>); 8fb943696SRichard Smith } 9fb943696SRichard Smith 10fb943696SRichard Smith namespace PR47025 { 11fb943696SRichard Smith template<typename ...T> concept AllAddable1 = requires(T ...t) { (void(t + 1), ...); }; 12fb943696SRichard Smith template<typename ...T> concept AllAddable2 = (requires(T ...t) { (t + 1); } && ...); // expected-error {{requirement contains unexpanded parameter pack 't'}} 13fb943696SRichard Smith template<typename ...T> concept AllAddable3 = (requires(T t) { (t + 1); } && ...); 14fb943696SRichard Smith template<typename ...T> concept AllAddable4 = requires(T t) { (t + 1); }; // expected-error {{expression contains unexpanded parameter pack 'T'}} 15fb943696SRichard Smith template<typename ...T> concept AllAddable5 = requires(T t) { (void(t + 1), ...); }; // expected-error {{does not contain any unexpanded}} 16fb943696SRichard Smith template<typename ...T> concept AllAddable6 = (requires { (T() + 1); } && ...); 17fb943696SRichard Smith template<typename ...T> concept AllAddable7 = requires { (T() + 1); }; // expected-error {{expression contains unexpanded parameter pack 'T'}} 18fb943696SRichard Smith 19fb943696SRichard Smith static_assert(AllAddable1<int, float>); 20fb943696SRichard Smith static_assert(AllAddable3<int, float>); 21fb943696SRichard Smith static_assert(AllAddable6<int, float>); 22fb943696SRichard Smith static_assert(!AllAddable1<int, void>); 23fb943696SRichard Smith static_assert(!AllAddable3<int, void>); 24fb943696SRichard Smith static_assert(!AllAddable6<int, void>); 25fb943696SRichard Smith } 26be162f4cSRichard Smith 27be162f4cSRichard Smith namespace PR45699 { 28be162f4cSRichard Smith template<class> concept C = true; // expected-note 2{{here}} 29be162f4cSRichard Smith template<class ...Ts> void f1a() requires C<Ts>; // expected-error {{requires clause contains unexpanded parameter pack 'Ts'}} 30be162f4cSRichard Smith template<class ...Ts> requires C<Ts> void f1b(); // expected-error {{requires clause contains unexpanded parameter pack 'Ts'}} 31be162f4cSRichard Smith template<class ...Ts> void f2a() requires (C<Ts> && ...); 32be162f4cSRichard Smith template<class ...Ts> requires (C<Ts> && ...) void f2b(); 33be162f4cSRichard Smith template<class ...Ts> void f3a() requires C<Ts...>; // expected-error {{pack expansion used as argument for non-pack parameter of concept}} 34be162f4cSRichard Smith template<class ...Ts> requires C<Ts...> void f3b(); // expected-error {{pack expansion used as argument for non-pack parameter of concept}} f4()35be162f4cSRichard Smith template<class ...Ts> void f4() { 36be162f4cSRichard Smith ([] () requires C<Ts> {} ()); // expected-error {{expression contains unexpanded parameter pack 'Ts'}} 37eccc734aSRichard Smith ([]<int = 0> requires C<Ts> () {} ()); // expected-error {{expression contains unexpanded parameter pack 'Ts'}} 38be162f4cSRichard Smith } f5()39be162f4cSRichard Smith template<class ...Ts> void f5() { 40be162f4cSRichard Smith ([] () requires C<Ts> {} (), ...); 41eccc734aSRichard Smith ([]<int = 0> requires C<Ts> () {} (), ...); 42be162f4cSRichard Smith } g()43be162f4cSRichard Smith void g() { 44be162f4cSRichard Smith f1a(); 45be162f4cSRichard Smith f1b(); // FIXME: Bad error recovery. expected-error {{undeclared identifier}} 46be162f4cSRichard Smith f2a(); 47be162f4cSRichard Smith f2b(); 48be162f4cSRichard Smith f3a(); 49be162f4cSRichard Smith f3b(); // FIXME: Bad error recovery. expected-error {{undeclared identifier}} 50be162f4cSRichard Smith f4(); 51be162f4cSRichard Smith f5(); 52be162f4cSRichard Smith } 53be162f4cSRichard Smith } 54eccc734aSRichard Smith 55eccc734aSRichard Smith namespace P0857R0 { f()56eccc734aSRichard Smith void f() { 57eccc734aSRichard Smith auto x = []<bool B> requires B {}; // expected-note {{constraints not satisfied}} expected-note {{false}} 58eccc734aSRichard Smith x.operator()<true>(); 59eccc734aSRichard Smith x.operator()<false>(); // expected-error {{no matching member function}} 60eccc734aSRichard Smith } 61eccc734aSRichard Smith 62eccc734aSRichard Smith // FIXME: This is valid under P0857R0. 63eccc734aSRichard Smith template<typename T> concept C = true; 64eccc734aSRichard Smith template<template<typename T> requires C<T> typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}} 65eccc734aSRichard Smith template<typename T> requires C<T> struct Y {}; 66eccc734aSRichard Smith X<Y> xy; // expected-error {{no template named 'X'}} 67eccc734aSRichard Smith } 682f9d8b08SRichard Smith 692f9d8b08SRichard Smith namespace PR50306 { 702f9d8b08SRichard Smith template<typename T> concept NotInt = sizeof(T) != sizeof(int); // expected-note {{because}} f()712f9d8b08SRichard Smith template<typename T> void f() { 722f9d8b08SRichard Smith [](NotInt auto) {}(T()); // expected-error {{no matching function}} expected-note {{constraints not satisfied}} expected-note {{because}} 732f9d8b08SRichard Smith } 742f9d8b08SRichard Smith template void f<char>(); // OK 752f9d8b08SRichard Smith template void f<int>(); // expected-note {{in instantiation of}} 762f9d8b08SRichard Smith } 77e1aa528dSRichard Smith 78e1aa528dSRichard Smith namespace PackInTypeConstraint { 79e1aa528dSRichard Smith template<typename T, typename U> concept C = sizeof(T) == sizeof(int); // expected-note 3{{}} 80e1aa528dSRichard Smith 81e1aa528dSRichard Smith template<typename ...T, C<T> U> void h1(); // expected-error {{type constraint contains unexpanded parameter pack 'T'}} 82e1aa528dSRichard Smith template<typename ...T, C<T> ...U> void h2(); 83e1aa528dSRichard Smith template<typename ...T> void h3(C<T> auto); // expected-error {{type constraint contains unexpanded parameter pack 'T'}} 84e1aa528dSRichard Smith template<typename ...T> void h4(C<T> auto...); 85e1aa528dSRichard Smith f1()86e1aa528dSRichard Smith template<typename ...T> void f1() { 87e1aa528dSRichard Smith []<C<T> U>(U u){}(T()); // expected-error {{unexpanded parameter pack 'T'}} 88e1aa528dSRichard Smith } f2()89e1aa528dSRichard Smith template<typename ...T> void f2() { 90e1aa528dSRichard Smith ([]<C<T> U>(U u){}(T()), ...); // expected-error {{no match}} expected-note 2{{}} 91e1aa528dSRichard Smith } 92e1aa528dSRichard Smith template void f2<int, int, int>(); // OK 93e1aa528dSRichard Smith template void f2<int, char, double>(); // expected-note {{in instantiation of}} f3()94e1aa528dSRichard Smith void f3() { 95e1aa528dSRichard Smith ([]<typename ...T, C<T> U>(U u){}(0), // expected-error {{type constraint contains unexpanded parameter pack 'T'}} 96e1aa528dSRichard Smith ...); // expected-error {{does not contain any unexpanded}} 97e1aa528dSRichard Smith } 98e1aa528dSRichard Smith g1()99e1aa528dSRichard Smith template<typename ...T> void g1() { 100e1aa528dSRichard Smith [](C<T> auto){}(T()); // expected-error {{expression contains unexpanded parameter pack 'T'}} 101e1aa528dSRichard Smith } g2()102e1aa528dSRichard Smith template<typename ...T> void g2() { 103e1aa528dSRichard Smith ([](C<T> auto){}(T()), ...); // expected-error {{no matching function}} expected-note {{constraints not satisfied}} expected-note {{because}} 104e1aa528dSRichard Smith } 105e1aa528dSRichard Smith template void g2<int, int, int>(); // OK 106e1aa528dSRichard Smith template void g2<int, char, double>(); // expected-note {{in instantiation of}} g3()107e1aa528dSRichard Smith void g3() { 108e1aa528dSRichard Smith ([]<typename ...T>(C<T> auto){}(1), // expected-error {{type constraint contains unexpanded parameter pack 'T'}} 109e1aa528dSRichard Smith ...); // expected-error {{does not contain any unexpanded}} 110e1aa528dSRichard Smith } 111e1aa528dSRichard Smith g4()112e1aa528dSRichard Smith template<typename ...T> void g4() { 113e1aa528dSRichard Smith []() -> C<T> auto{ return T(); }(); // expected-error {{expression contains unexpanded parameter pack 'T'}} 114e1aa528dSRichard Smith } g5()115e1aa528dSRichard Smith template<typename ...T> void g5() { 116e1aa528dSRichard Smith ([]() -> C<T> auto{ // expected-error-re {{deduced type {{.*}} does not satisfy}} 117e1aa528dSRichard Smith return T(); 118e1aa528dSRichard Smith }(), ...); 119e1aa528dSRichard Smith } 120e1aa528dSRichard Smith template void g5<int, int, int>(); // OK 121e1aa528dSRichard Smith template void g5<int, char, double>(); // expected-note {{in instantiation of}} g6()122e1aa528dSRichard Smith void g6() { 123e1aa528dSRichard Smith ([]<typename ...T>() -> C<T> auto{ // expected-error {{declaration type contains unexpanded parameter pack 'T'}} 124e1aa528dSRichard Smith return T(); // expected-error {{expression contains unexpanded parameter pack 'T'}} 125e1aa528dSRichard Smith }(), 126e1aa528dSRichard Smith ...); // expected-error {{does not contain any unexpanded}} 127e1aa528dSRichard Smith } 128e1aa528dSRichard Smith } 1292f8ac075SRichard Smith 1302f8ac075SRichard Smith namespace BuiltinIsConstantEvaluated { 1312f8ac075SRichard Smith // Check that we do all satisfaction and diagnostic checks in a constant context. 1322f8ac075SRichard Smith template<typename T> concept C = __builtin_is_constant_evaluated(); // expected-warning {{always}} 1332f8ac075SRichard Smith static_assert(C<int>); 1342f8ac075SRichard Smith 1352f8ac075SRichard Smith template<typename T> concept D = __builtin_is_constant_evaluated() == true; // expected-warning {{always}} 1362f8ac075SRichard Smith static_assert(D<int>); 1372f8ac075SRichard Smith 1382f8ac075SRichard Smith template<typename T> concept E = __builtin_is_constant_evaluated() == true && // expected-warning {{always}} 1392f8ac075SRichard Smith false; // expected-note {{'false' evaluated to false}} 1402f8ac075SRichard Smith static_assert(E<int>); // expected-error {{failed}} expected-note {{because 'int' does not satisfy 'E'}} 1412f8ac075SRichard Smith 1422f8ac075SRichard Smith template<typename T> concept F = __builtin_is_constant_evaluated() == false; // expected-warning {{always}} 1432f8ac075SRichard Smith // expected-note@-1 {{'__builtin_is_constant_evaluated() == false' (1 == 0)}} 1442f8ac075SRichard Smith static_assert(F<int>); // expected-error {{failed}} expected-note {{because 'int' does not satisfy 'F'}} 1452f8ac075SRichard Smith 1462f8ac075SRichard Smith template<typename T> concept G = __builtin_is_constant_evaluated() && // expected-warning {{always}} 1472f8ac075SRichard Smith false; // expected-note {{'false' evaluated to false}} 1482f8ac075SRichard Smith static_assert(G<int>); // expected-error {{failed}} expected-note {{because 'int' does not satisfy 'G'}} 1492f8ac075SRichard Smith } 1502f8ac075SRichard Smith 1512f8ac075SRichard Smith namespace NoConstantFolding { 1522f8ac075SRichard Smith // Ensure we use strict constant evaluation rules when checking satisfaction. 1532f8ac075SRichard Smith int n; 1542f8ac075SRichard Smith 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}} 1552f8ac075SRichard Smith static_assert(C<void>); // expected-note {{while checking}} 1562f8ac075SRichard Smith } 15713659f48SRichard Smith 15813659f48SRichard Smith namespace PR50337 { 15913659f48SRichard Smith template <typename T> concept foo = true; 16013659f48SRichard Smith template <typename T> concept foo2 = foo<T> && true; 16113659f48SRichard Smith void f(foo auto, auto); 16213659f48SRichard Smith void f(foo2 auto, auto); g()16313659f48SRichard Smith void g() { f(1, 2); } 16413659f48SRichard Smith } 16513659f48SRichard Smith 16613659f48SRichard Smith namespace PR50561 { 16713659f48SRichard Smith template<typename> concept C = false; 16813659f48SRichard Smith template<typename T, typename U> void f(T, U); 16913659f48SRichard Smith template<C T, typename U> void f(T, U) = delete; g()17013659f48SRichard Smith void g() { f(0, 0); } 17113659f48SRichard Smith } 172f0891cd6SArthur O'Dwyer 173f0891cd6SArthur O'Dwyer namespace PR49188 { 174*94fd00f4SRoy Jacobson template<class T> concept C = false; // expected-note 7 {{because 'false' evaluated to false}} 175f0891cd6SArthur O'Dwyer f1()176f0891cd6SArthur O'Dwyer C auto f1() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 177f0891cd6SArthur O'Dwyer return void(); 178f0891cd6SArthur O'Dwyer } f2()179f0891cd6SArthur O'Dwyer C auto f2() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 180f0891cd6SArthur O'Dwyer return; 181f0891cd6SArthur O'Dwyer } f3()182f0891cd6SArthur O'Dwyer C auto f3() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 183f0891cd6SArthur O'Dwyer } f4()184f0891cd6SArthur O'Dwyer C decltype(auto) f4() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 185f0891cd6SArthur O'Dwyer return void(); 186f0891cd6SArthur O'Dwyer } f5()187f0891cd6SArthur O'Dwyer C decltype(auto) f5() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 188f0891cd6SArthur O'Dwyer return; 189f0891cd6SArthur O'Dwyer } f6()190f0891cd6SArthur O'Dwyer C decltype(auto) f6() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 191f0891cd6SArthur O'Dwyer } f7()192*94fd00f4SRoy Jacobson C auto& f7() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 193f0891cd6SArthur O'Dwyer return void(); 194f0891cd6SArthur O'Dwyer } f8()195f0891cd6SArthur O'Dwyer C auto& f8() { 196f0891cd6SArthur O'Dwyer return; // expected-error {{cannot deduce return type 'C auto &' from omitted return expression}} 197f0891cd6SArthur O'Dwyer } f9()198f0891cd6SArthur O'Dwyer C auto& f9() { // expected-error {{cannot deduce return type 'C auto &' for function with no return statements}} 199f0891cd6SArthur O'Dwyer } 200f0891cd6SArthur O'Dwyer } 201f0891cd6SArthur O'Dwyer namespace PR53911 { 202*94fd00f4SRoy Jacobson template<class T> concept C = false; // expected-note 3 {{because 'false' evaluated to false}} 203f0891cd6SArthur O'Dwyer f1()204*94fd00f4SRoy Jacobson C auto *f1() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 205*94fd00f4SRoy Jacobson return (void*)nullptr; 206f0891cd6SArthur O'Dwyer } f2()207*94fd00f4SRoy Jacobson C auto *f2() { // expected-error {{deduced type 'int' does not satisfy 'C'}} 208*94fd00f4SRoy Jacobson return (int*)nullptr; 209*94fd00f4SRoy Jacobson } f3()210*94fd00f4SRoy Jacobson C auto *****f3() { // expected-error {{deduced type 'int' does not satisfy 'C'}} 211*94fd00f4SRoy Jacobson return (int*****)nullptr; 212f0891cd6SArthur O'Dwyer } 213f0891cd6SArthur O'Dwyer } 214bc7034c1SRoy Jacobson 215bc7034c1SRoy Jacobson namespace PR54379 { 216bc7034c1SRoy Jacobson template <int N> 217bc7034c1SRoy Jacobson struct A { fPR54379::A218bc7034c1SRoy Jacobson static void f() requires (N == 0) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}} fPR54379::A219bc7034c1SRoy Jacobson static void f() requires (N == 1) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}} 220bc7034c1SRoy Jacobson }; 221bc7034c1SRoy Jacobson void (*f1)() = A<2>::f; // expected-error {{address of overloaded function 'f' does not match required type}} 222bc7034c1SRoy Jacobson 223bc7034c1SRoy Jacobson struct B { fPR54379::B224bc7034c1SRoy Jacobson 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}} 225bc7034c1SRoy Jacobson }; 226bc7034c1SRoy Jacobson void (*f2)() = B::f; // expected-error {{address of overloaded function 'f' does not match required type}} 227bc7034c1SRoy Jacobson } 228*94fd00f4SRoy Jacobson 229*94fd00f4SRoy Jacobson namespace PR54443 { 230*94fd00f4SRoy Jacobson 231*94fd00f4SRoy Jacobson template <class T, class U> 232*94fd00f4SRoy Jacobson struct is_same { static constexpr bool value = false; }; 233*94fd00f4SRoy Jacobson 234*94fd00f4SRoy Jacobson template <class T> 235*94fd00f4SRoy Jacobson struct is_same<T, T> { static constexpr bool value = true; }; 236*94fd00f4SRoy Jacobson 237*94fd00f4SRoy Jacobson template <class T, class U> 238*94fd00f4SRoy Jacobson concept same_as = is_same<T, U>::value; // expected-note-re 4 {{because {{.*}} evaluated to false}} 239*94fd00f4SRoy Jacobson 240*94fd00f4SRoy Jacobson int const &f(); 241*94fd00f4SRoy Jacobson 242*94fd00f4SRoy Jacobson same_as<int const> auto i1 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as<const int>'}} 243*94fd00f4SRoy Jacobson same_as<int const> auto &i2 = f(); 244*94fd00f4SRoy Jacobson same_as<int const> auto &&i3 = f(); // expected-error {{deduced type 'const int &' does not satisfy 'same_as<const int>'}} 245*94fd00f4SRoy Jacobson 246*94fd00f4SRoy Jacobson same_as<int const &> auto i4 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as<const int &>'}} 247*94fd00f4SRoy Jacobson same_as<int const &> auto &i5 = f(); // expected-error {{deduced type 'const int' does not satisfy 'same_as<const int &>'}} 248*94fd00f4SRoy Jacobson same_as<int const &> auto &&i6 = f(); 249*94fd00f4SRoy Jacobson 250*94fd00f4SRoy Jacobson template <class T> 251*94fd00f4SRoy Jacobson concept C = false; // expected-note 3 {{because 'false' evaluated to false}} 252*94fd00f4SRoy Jacobson 253*94fd00f4SRoy Jacobson int **const &g(); 254*94fd00f4SRoy Jacobson 255*94fd00f4SRoy Jacobson C auto **j1 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}} 256*94fd00f4SRoy Jacobson C auto **&j2 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}} 257*94fd00f4SRoy Jacobson C auto **&&j3 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}} 258*94fd00f4SRoy Jacobson } 259