1 // RUN: %clang_cc1 -std=c++20 -verify %s 2 3 namespace PR47043 { 4 template<typename T> concept True = true; 5 template<typename ...T> concept AllTrue1 = True<T>; // expected-error {{expression contains unexpanded parameter pack 'T'}} 6 template<typename ...T> concept AllTrue2 = (True<T> && ...); 7 static_assert(AllTrue2<int, float, char>); 8 } 9 10 namespace PR47025 { 11 template<typename ...T> concept AllAddable1 = requires(T ...t) { (void(t + 1), ...); }; 12 template<typename ...T> concept AllAddable2 = (requires(T ...t) { (t + 1); } && ...); // expected-error {{requirement contains unexpanded parameter pack 't'}} 13 template<typename ...T> concept AllAddable3 = (requires(T t) { (t + 1); } && ...); 14 template<typename ...T> concept AllAddable4 = requires(T t) { (t + 1); }; // expected-error {{expression contains unexpanded parameter pack 'T'}} 15 template<typename ...T> concept AllAddable5 = requires(T t) { (void(t + 1), ...); }; // expected-error {{does not contain any unexpanded}} 16 template<typename ...T> concept AllAddable6 = (requires { (T() + 1); } && ...); 17 template<typename ...T> concept AllAddable7 = requires { (T() + 1); }; // expected-error {{expression contains unexpanded parameter pack 'T'}} 18 19 static_assert(AllAddable1<int, float>); 20 static_assert(AllAddable3<int, float>); 21 static_assert(AllAddable6<int, float>); 22 static_assert(!AllAddable1<int, void>); 23 static_assert(!AllAddable3<int, void>); 24 static_assert(!AllAddable6<int, void>); 25 } 26 27 namespace PR45699 { 28 template<class> concept C = true; // expected-note 2{{here}} 29 template<class ...Ts> void f1a() requires C<Ts>; // expected-error {{requires clause contains unexpanded parameter pack 'Ts'}} 30 template<class ...Ts> requires C<Ts> void f1b(); // expected-error {{requires clause contains unexpanded parameter pack 'Ts'}} 31 template<class ...Ts> void f2a() requires (C<Ts> && ...); 32 template<class ...Ts> requires (C<Ts> && ...) void f2b(); 33 template<class ...Ts> void f3a() requires C<Ts...>; // expected-error {{pack expansion used as argument for non-pack parameter of concept}} 34 template<class ...Ts> requires C<Ts...> void f3b(); // expected-error {{pack expansion used as argument for non-pack parameter of concept}} f4()35 template<class ...Ts> void f4() { 36 ([] () requires C<Ts> {} ()); // expected-error {{expression contains unexpanded parameter pack 'Ts'}} 37 ([]<int = 0> requires C<Ts> () {} ()); // expected-error {{expression contains unexpanded parameter pack 'Ts'}} 38 } f5()39 template<class ...Ts> void f5() { 40 ([] () requires C<Ts> {} (), ...); 41 ([]<int = 0> requires C<Ts> () {} (), ...); 42 } g()43 void g() { 44 f1a(); 45 f1b(); // FIXME: Bad error recovery. expected-error {{undeclared identifier}} 46 f2a(); 47 f2b(); 48 f3a(); 49 f3b(); // FIXME: Bad error recovery. expected-error {{undeclared identifier}} 50 f4(); 51 f5(); 52 } 53 } 54 55 namespace P0857R0 { f()56 void f() { 57 auto x = []<bool B> requires B {}; // expected-note {{constraints not satisfied}} expected-note {{false}} 58 x.operator()<true>(); 59 x.operator()<false>(); // expected-error {{no matching member function}} 60 } 61 62 // FIXME: This is valid under P0857R0. 63 template<typename T> concept C = true; 64 template<template<typename T> requires C<T> typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}} 65 template<typename T> requires C<T> struct Y {}; 66 X<Y> xy; // expected-error {{no template named 'X'}} 67 } 68 69 namespace PR50306 { 70 template<typename T> concept NotInt = sizeof(T) != sizeof(int); // expected-note {{because}} f()71 template<typename T> void f() { 72 [](NotInt auto) {}(T()); // expected-error {{no matching function}} expected-note {{constraints not satisfied}} expected-note {{because}} 73 } 74 template void f<char>(); // OK 75 template void f<int>(); // expected-note {{in instantiation of}} 76 } 77 78 namespace PackInTypeConstraint { 79 template<typename T, typename U> concept C = sizeof(T) == sizeof(int); // expected-note 3{{}} 80 81 template<typename ...T, C<T> U> void h1(); // expected-error {{type constraint contains unexpanded parameter pack 'T'}} 82 template<typename ...T, C<T> ...U> void h2(); 83 template<typename ...T> void h3(C<T> auto); // expected-error {{type constraint contains unexpanded parameter pack 'T'}} 84 template<typename ...T> void h4(C<T> auto...); 85 f1()86 template<typename ...T> void f1() { 87 []<C<T> U>(U u){}(T()); // expected-error {{unexpanded parameter pack 'T'}} 88 } f2()89 template<typename ...T> void f2() { 90 ([]<C<T> U>(U u){}(T()), ...); // expected-error {{no match}} expected-note 2{{}} 91 } 92 template void f2<int, int, int>(); // OK 93 template void f2<int, char, double>(); // expected-note {{in instantiation of}} f3()94 void f3() { 95 ([]<typename ...T, C<T> U>(U u){}(0), // expected-error {{type constraint contains unexpanded parameter pack 'T'}} 96 ...); // expected-error {{does not contain any unexpanded}} 97 } 98 g1()99 template<typename ...T> void g1() { 100 [](C<T> auto){}(T()); // expected-error {{expression contains unexpanded parameter pack 'T'}} 101 } g2()102 template<typename ...T> void g2() { 103 ([](C<T> auto){}(T()), ...); // expected-error {{no matching function}} expected-note {{constraints not satisfied}} expected-note {{because}} 104 } 105 template void g2<int, int, int>(); // OK 106 template void g2<int, char, double>(); // expected-note {{in instantiation of}} g3()107 void g3() { 108 ([]<typename ...T>(C<T> auto){}(1), // expected-error {{type constraint contains unexpanded parameter pack 'T'}} 109 ...); // expected-error {{does not contain any unexpanded}} 110 } 111 g4()112 template<typename ...T> void g4() { 113 []() -> C<T> auto{ return T(); }(); // expected-error {{expression contains unexpanded parameter pack 'T'}} 114 } g5()115 template<typename ...T> void g5() { 116 ([]() -> C<T> auto{ // expected-error-re {{deduced type {{.*}} does not satisfy}} 117 return T(); 118 }(), ...); 119 } 120 template void g5<int, int, int>(); // OK 121 template void g5<int, char, double>(); // expected-note {{in instantiation of}} g6()122 void g6() { 123 ([]<typename ...T>() -> C<T> auto{ // expected-error {{declaration type contains unexpanded parameter pack 'T'}} 124 return T(); // expected-error {{expression contains unexpanded parameter pack 'T'}} 125 }(), 126 ...); // expected-error {{does not contain any unexpanded}} 127 } 128 } 129 130 namespace BuiltinIsConstantEvaluated { 131 // Check that we do all satisfaction and diagnostic checks in a constant context. 132 template<typename T> concept C = __builtin_is_constant_evaluated(); // expected-warning {{always}} 133 static_assert(C<int>); 134 135 template<typename T> concept D = __builtin_is_constant_evaluated() == true; // expected-warning {{always}} 136 static_assert(D<int>); 137 138 template<typename T> concept E = __builtin_is_constant_evaluated() == true && // expected-warning {{always}} 139 false; // expected-note {{'false' evaluated to false}} 140 static_assert(E<int>); // expected-error {{failed}} expected-note {{because 'int' does not satisfy 'E'}} 141 142 template<typename T> concept F = __builtin_is_constant_evaluated() == false; // expected-warning {{always}} 143 // expected-note@-1 {{'__builtin_is_constant_evaluated() == false' (1 == 0)}} 144 static_assert(F<int>); // expected-error {{failed}} expected-note {{because 'int' does not satisfy 'F'}} 145 146 template<typename T> concept G = __builtin_is_constant_evaluated() && // expected-warning {{always}} 147 false; // expected-note {{'false' evaluated to false}} 148 static_assert(G<int>); // expected-error {{failed}} expected-note {{because 'int' does not satisfy 'G'}} 149 } 150 151 namespace NoConstantFolding { 152 // Ensure we use strict constant evaluation rules when checking satisfaction. 153 int n; 154 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}} 155 static_assert(C<void>); // expected-note {{while checking}} 156 } 157 158 namespace PR50337 { 159 template <typename T> concept foo = true; 160 template <typename T> concept foo2 = foo<T> && true; 161 void f(foo auto, auto); 162 void f(foo2 auto, auto); g()163 void g() { f(1, 2); } 164 } 165 166 namespace PR50561 { 167 template<typename> concept C = false; 168 template<typename T, typename U> void f(T, U); 169 template<C T, typename U> void f(T, U) = delete; g()170 void g() { f(0, 0); } 171 } 172 173 namespace PR49188 { 174 template<class T> concept C = false; // expected-note 7 {{because 'false' evaluated to false}} 175 f1()176 C auto f1() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 177 return void(); 178 } f2()179 C auto f2() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 180 return; 181 } f3()182 C auto f3() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 183 } f4()184 C decltype(auto) f4() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 185 return void(); 186 } f5()187 C decltype(auto) f5() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 188 return; 189 } f6()190 C decltype(auto) f6() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 191 } f7()192 C auto& f7() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 193 return void(); 194 } f8()195 C auto& f8() { 196 return; // expected-error {{cannot deduce return type 'C auto &' from omitted return expression}} 197 } f9()198 C auto& f9() { // expected-error {{cannot deduce return type 'C auto &' for function with no return statements}} 199 } 200 } 201 namespace PR53911 { 202 template<class T> concept C = false; // expected-note 3 {{because 'false' evaluated to false}} 203 f1()204 C auto *f1() { // expected-error {{deduced type 'void' does not satisfy 'C'}} 205 return (void*)nullptr; 206 } f2()207 C auto *f2() { // expected-error {{deduced type 'int' does not satisfy 'C'}} 208 return (int*)nullptr; 209 } f3()210 C auto *****f3() { // expected-error {{deduced type 'int' does not satisfy 'C'}} 211 return (int*****)nullptr; 212 } 213 } 214 215 namespace PR54379 { 216 template <int N> 217 struct A { fPR54379::A218 static void f() requires (N == 0) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}} fPR54379::A219 static void f() requires (N == 1) { return; } // expected-note {{candidate template ignored: constraints not satisfied}} expected-note {{evaluated to false}} 220 }; 221 void (*f1)() = A<2>::f; // expected-error {{address of overloaded function 'f' does not match required type}} 222 223 struct B { fPR54379::B224 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}} 225 }; 226 void (*f2)() = B::f; // expected-error {{address of overloaded function 'f' does not match required type}} 227 } 228 229 namespace PR54443 { 230 231 template <class T, class U> 232 struct is_same { static constexpr bool value = false; }; 233 234 template <class T> 235 struct is_same<T, T> { static constexpr bool value = true; }; 236 237 template <class T, class U> 238 concept same_as = is_same<T, U>::value; // expected-note-re 4 {{because {{.*}} evaluated to false}} 239 240 int const &f(); 241 242 same_as<int const> auto i1 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as<const int>'}} 243 same_as<int const> auto &i2 = f(); 244 same_as<int const> auto &&i3 = f(); // expected-error {{deduced type 'const int &' does not satisfy 'same_as<const int>'}} 245 246 same_as<int const &> auto i4 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as<const int &>'}} 247 same_as<int const &> auto &i5 = f(); // expected-error {{deduced type 'const int' does not satisfy 'same_as<const int &>'}} 248 same_as<int const &> auto &&i6 = f(); 249 250 template <class T> 251 concept C = false; // expected-note 3 {{because 'false' evaluated to false}} 252 253 int **const &g(); 254 255 C auto **j1 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}} 256 C auto **&j2 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}} 257 C auto **&&j3 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}} 258 } 259