| 1 |
// RUN: %clang_cc1 -std=c++20 -ferror-limit 0 -verify=expected,cxx20 %s |
| 2 |
// RUN: %clang_cc1 -std=c++2c -ferror-limit 0 -verify=expected %s |
| 3 |
|
| 4 |
namespace 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 |
|
| 13 |
namespace 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 |
|
| 30 |
namespace 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 |
|
| 58 |
namespace 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>(); // OK |
| 68 |
} |
| 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 |
|
| 76 |
namespace 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>(); // OK |
| 82 |
template void f<int>(); // expected-note {{in instantiation of}} |
| 83 |
} |
| 84 |
|
| 85 |
namespace 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>(); // OK |
| 100 |
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>(); // OK |
| 113 |
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>(); // OK |
| 128 |
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 |
|
| 137 |
namespace 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 |
|
| 158 |
namespace 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 |
|
| 165 |
namespace 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 |
|
| 173 |
namespace 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 |
|
| 180 |
namespace 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 |
} |
| 208 |
namespace 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 |
|
| 222 |
namespace PR54379 { |
| 223 |
template <int N> |
| 224 |
struct 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 |
}; |
| 228 |
void (*f1)() = A<2>::f; // expected-error {{address of overloaded function 'f' does not match required type}} |
| 229 |
|
| 230 |
struct 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 |
}; |
| 233 |
void (*f2)() = B::f; // expected-error {{address of overloaded function 'f' does not match required type}} |
| 234 |
} |
| 235 |
|
| 236 |
namespace PR54443 { |
| 237 |
|
| 238 |
template <class T, class U> |
| 239 |
struct is_same { static constexpr bool value = false; }; |
| 240 |
|
| 241 |
template <class T> |
| 242 |
struct is_same<T, T> { static constexpr bool value = true; }; |
| 243 |
|
| 244 |
template <class T, class U> |
| 245 |
concept same_as = is_same<T, U>::value; // expected-note-re 4 {{because {{.*}} evaluated to false}} |
| 246 |
|
| 247 |
int const &f(); |
| 248 |
|
| 249 |
same_as<int const> auto i1 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as<const int>'}} |
| 250 |
same_as<int const> auto &i2 = f(); |
| 251 |
same_as<int const> auto &&i3 = f(); // expected-error {{deduced type 'const int &' does not satisfy 'same_as<const int>'}} |
| 252 |
|
| 253 |
same_as<int const &> auto i4 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as<const int &>'}} |
| 254 |
same_as<int const &> auto &i5 = f(); // expected-error {{deduced type 'const int' does not satisfy 'same_as<const int &>'}} |
| 255 |
same_as<int const &> auto &&i6 = f(); |
| 256 |
|
| 257 |
template <class T> |
| 258 |
concept C = false; // expected-note 3 {{because 'false' evaluated to false}} |
| 259 |
|
| 260 |
int **const &g(); |
| 261 |
|
| 262 |
C auto **j1 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}} |
| 263 |
C auto **&j2 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}} |
| 264 |
C auto **&&j3 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}} |
| 265 |
} |
| 266 |
|
| 267 |
namespace GH55567 { |
| 268 |
template<class, template <class> class> concept C = true; |
| 269 |
template <class> struct S {}; |
| 270 |
void f(C<GH55567::S> auto); |
| 271 |
} // namespace GH55567 |
| 272 |
|
| 273 |
namespace SubConstraintChecks { |
| 274 |
template <typename T> |
| 275 |
concept TrueConstraint = true; |
| 276 |
template <typename T> |
| 277 |
concept FalseConstraint = false; |
| 278 |
|
| 279 |
template <typename T, typename... Us> |
| 280 |
class ContainsConstrainedFuncTrue { |
| 281 |
public: |
| 282 |
template <typename V, TrueConstraint Constrained> |
| 283 |
static void func(V &&, Constrained &&C); |
| 284 |
}; |
| 285 |
template <typename T, typename... Us> |
| 286 |
class ContainsConstrainedFuncFalse { |
| 287 |
public: |
| 288 |
template <typename V, FalseConstraint Constrained> |
| 289 |
static void func(V &&, Constrained &&C); |
| 290 |
}; |
| 291 |
|
| 292 |
template <typename... Us> |
| 293 |
concept TrueConstraint2 = |
| 294 |
requires(float &&t) { |
| 295 |
ContainsConstrainedFuncTrue<float, Us...>::func(5, 0.0); |
| 296 |
}; |
| 297 |
template <typename... Us> |
| 298 |
concept FalseConstraint2 = |
| 299 |
requires(float &&t) { |
| 300 |
ContainsConstrainedFuncFalse<float, Us...>::func(5, 0.0); // #FC2_CONSTR |
| 301 |
}; |
| 302 |
|
| 303 |
template <typename T> |
| 304 |
void useTrue(int F) |
| 305 |
requires TrueConstraint2<int> |
| 306 |
{} |
| 307 |
|
| 308 |
template <typename T> |
| 309 |
void useFalse(int F) // #USE_FALSE |
| 310 |
requires FalseConstraint2<int> // #USE_FALSE_CONSTR |
| 311 |
{} |
| 312 |
|
| 313 |
// Should only diagnose 'false' once instantiated. |
| 314 |
void 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 SubConstraintChecks |
| 323 |
|
| 324 |
namespace DeducedTemplateArgs { |
| 325 |
template <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_PTR |
| 334 |
}; |
| 335 |
|
| 336 |
struct complete_itr { |
| 337 |
using pointer = int; |
| 338 |
}; |
| 339 |
|
| 340 |
template <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 first |
| 346 |
// verison of 'Ptr'. |
| 347 |
struct not_complete_itr { |
| 348 |
}; |
| 349 |
|
| 350 |
template <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 DeducedTemplateArgs |
| 357 |
|
| 358 |
namespace DeferredInstantiationInstScope { |
| 359 |
template <typename T> |
| 360 |
struct remove_ref { |
| 361 |
using type = T; |
| 362 |
}; |
| 363 |
template <typename T> |
| 364 |
struct remove_ref<T &> { |
| 365 |
using type = T; |
| 366 |
}; |
| 367 |
template <typename T> |
| 368 |
struct remove_ref<T &&> { |
| 369 |
using type = T; |
| 370 |
}; |
| 371 |
|
| 372 |
template <typename T> |
| 373 |
constexpr bool IsInt = PR54443::is_same<typename remove_ref<T>::type, |
| 374 |
int>::value; |
| 375 |
|
| 376 |
template <typename U> |
| 377 |
void SingleDepthReferencesTop(U &&u) { |
| 378 |
struct lc { |
| 379 |
void operator()() // #SDRT_OP |
| 380 |
requires IsInt<decltype(u)> // #SDRT_REQ |
| 381 |
{} |
| 382 |
}; |
| 383 |
lc lv; |
| 384 |
lv(); // #SDRT_CALL |
| 385 |
} |
| 386 |
|
| 387 |
template <typename U> |
| 388 |
void SingleDepthReferencesTopNotCalled(U &&u) { |
| 389 |
struct lc { |
| 390 |
void operator()() |
| 391 |
requires IsInt<typename decltype(u)::FOO> |
| 392 |
{} |
| 393 |
}; |
| 394 |
lc lv; |
| 395 |
} |
| 396 |
|
| 397 |
template <typename U> |
| 398 |
void SingleDepthReferencesTopCalled(U &&u) { |
| 399 |
struct lc { |
| 400 |
void operator()() // #CALLOP |
| 401 |
requires IsInt<typename decltype(u)::FOO> // #CONSTR |
| 402 |
{} |
| 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 |
|
| 412 |
template <typename U> |
| 413 |
void SingleDepthReferencesTopLambda(U &&u) { |
| 414 |
[]() // #SDRTL_OP |
| 415 |
requires IsInt<decltype(u)> // #SDRTL_REQ |
| 416 |
{}(); |
| 417 |
} |
| 418 |
|
| 419 |
template <typename U> |
| 420 |
void DoubleDepthReferencesTop(U &&u) { |
| 421 |
struct lc { // #DDRT_STRCT |
| 422 |
void operator()() { |
| 423 |
struct lc2 { |
| 424 |
void operator()() // #DDRT_OP |
| 425 |
requires IsInt<decltype(u)> // #DDRT_REQ |
| 426 |
{} |
| 427 |
}; |
| 428 |
lc2 lv2; |
| 429 |
lv2(); // #DDRT_CALL |
| 430 |
} |
| 431 |
}; |
| 432 |
lc lv; |
| 433 |
lv(); |
| 434 |
} |
| 435 |
|
| 436 |
template <typename U> |
| 437 |
void DoubleDepthReferencesTopLambda(U &&u) { |
| 438 |
[]() { []() // #DDRTL_OP |
| 439 |
requires IsInt<decltype(u)> // #DDRTL_REQ |
| 440 |
{}(); }(); |
| 441 |
} |
| 442 |
|
| 443 |
template <typename U> |
| 444 |
void DoubleDepthReferencesAll(U &&u) { |
| 445 |
struct lc { // #DDRA_STRCT |
| 446 |
void operator()(U &&u2) { |
| 447 |
struct lc2 { |
| 448 |
void operator()(U &&u3) // #DDRA_OP |
| 449 |
requires IsInt<decltype(u)> && // #DDRA_REQ |
| 450 |
IsInt<decltype(u2)> && IsInt<decltype(u3)> |
| 451 |
{} |
| 452 |
}; |
| 453 |
lc2 lv2; |
| 454 |
lv2(u2); // #DDRA_CALL |
| 455 |
} |
| 456 |
}; |
| 457 |
lc lv; |
| 458 |
lv(u); |
| 459 |
} |
| 460 |
|
| 461 |
template <typename U> |
| 462 |
void DoubleDepthReferencesAllLambda(U &&u) { |
| 463 |
[](U &&u2) { // #DDRAL_OP1 |
| 464 |
[](U && u3) // #DDRAL_OP2 |
| 465 |
requires IsInt<decltype(u)> // #DDRAL_REQ |
| 466 |
&& IsInt<decltype(u2)> |
| 467 |
&& IsInt<decltype(u3)> |
| 468 |
{}(u2); |
| 469 |
}(u); |
| 470 |
} |
| 471 |
|
| 472 |
template <typename U> |
| 473 |
struct CausesFriendConstraint { |
| 474 |
template <typename V> |
| 475 |
friend void FriendFunc(CausesFriendConstraint, V) // #FF_DECL |
| 476 |
requires IsInt<U> && |
| 477 |
IsInt<V> // #FF_REQ |
| 478 |
{} |
| 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 |
|
| 486 |
template <typename T> |
| 487 |
void ChecksLocalVar(T x) { |
| 488 |
T Local; |
| 489 |
[]() // #CLV_OP |
| 490 |
requires(IsInt<decltype(Local)>) // #CLV_REQ |
| 491 |
{}(); |
| 492 |
} |
| 493 |
|
| 494 |
template <typename T> |
| 495 |
void LocalStructMemberVar(T x) { |
| 496 |
struct S { |
| 497 |
T local; |
| 498 |
void foo() |
| 499 |
requires(IsInt<decltype(local)>) // #LSMV_REQ |
| 500 |
{} |
| 501 |
} s; |
| 502 |
s.foo(); // #LSMV_CALL |
| 503 |
}; |
| 504 |
|
| 505 |
template <typename T> |
| 506 |
struct ChecksMemberVar { |
| 507 |
T t; |
| 508 |
void foo() |
| 509 |
requires(IsInt<decltype(t)>) // #CMV_FOO |
| 510 |
{} |
| 511 |
template <typename U> |
| 512 |
void foo2() // #CMV_FOO2 |
| 513 |
requires(IsInt<decltype(t)>) // #CMV_FOO2_REQ |
| 514 |
{} |
| 515 |
}; |
| 516 |
|
| 517 |
void 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); // #SDRTC |
| 531 |
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 DeferredInstantiationInstScope |
| 608 |
|
| 609 |
// Ane example of evaluating a concept at two different depths in the same |
| 610 |
// evaluation. No diagnostic is expected. |
| 611 |
namespace SameConceptDifferentDepth { |
| 612 |
template <class _Ip> |
| 613 |
concept sentinel_for = |
| 614 |
requires(_Ip __i) { |
| 615 |
__i++; |
| 616 |
}; |
| 617 |
|
| 618 |
template <class _Ip> |
| 619 |
concept bidirectional_iterator = |
| 620 |
sentinel_for<_Ip>; |
| 621 |
|
| 622 |
template <class _Iter> |
| 623 |
class move_iterator { |
| 624 |
public: |
| 625 |
auto operator++(int) |
| 626 |
requires sentinel_for<_Iter>{} |
| 627 |
}; |
| 628 |
|
| 629 |
static_assert(bidirectional_iterator<move_iterator<int>>); |
| 630 |
} // namespace SameConceptDifferentDepth |
| 631 |
|
| 632 |
namespace VarInit { |
| 633 |
template <class _Tp> |
| 634 |
concept __can_reference = true; |
| 635 |
|
| 636 |
template <class _Iter> |
| 637 |
class common_iterator { |
| 638 |
public: |
| 639 |
common_iterator() { |
| 640 |
constexpr auto x = requires(_Iter & __i) { { __i } -> __can_reference; }; |
| 641 |
} |
| 642 |
}; |
| 643 |
|
| 644 |
void test() { |
| 645 |
auto commonIter1 = common_iterator<int>(); |
| 646 |
} |
| 647 |
} // namespace VarInit |
| 648 |
|
| 649 |
|
| 650 |
namespace InlineFriendOperator { |
| 651 |
template <typename T> |
| 652 |
concept C = true; |
| 653 |
template <class _Iter> |
| 654 |
class counted_iterator { |
| 655 |
_Iter I; |
| 656 |
public: |
| 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 |
|
| 666 |
constexpr 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 InlineFriendOperator |
| 673 |
|
| 674 |
namespace ClassTemplateInstantiation { |
| 675 |
struct Type; |
| 676 |
template < typename A, typename B, typename C> |
| 677 |
concept ConstraintF = false; // #ConstraintF |
| 678 |
template < typename A, typename B, typename C> |
| 679 |
concept ConstraintT = true; |
| 680 |
|
| 681 |
template < 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{};// #ChildF |
| 685 |
ChildF<Type, Type> CauseInstF; //#CauseInstF |
| 686 |
}; |
| 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}} |
| 692 |
Parent<int> Inst; |
| 693 |
} // namespace ClassTemplateInstantiation |
| 694 |
|
| 695 |
namespace 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_BAD |
| 709 |
struct IteratorBad { |
| 710 |
template <Constraint2>//#ITER_BAD_FRIEND |
| 711 |
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 SelfFriend |
| 721 |
|
| 722 |
|
| 723 |
namespace Surrogates { |
| 724 |
int f1(int); |
| 725 |
template <auto N> |
| 726 |
struct 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 |
}; |
| 730 |
int i = A<true>{}(0); |
| 731 |
int j = A<false>{}(0); // expected-error{{no matching function for call to object of type 'A<false>'}} |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
namespace ConstrainedMemberVarTemplate { |
| 736 |
template <long Size> struct Container { |
| 737 |
static constexpr long arity = Size; |
| 738 |
template <typename U> |
| 739 |
requires(sizeof(U) == arity) // #CMVT_REQ |
| 740 |
using var_templ = int; |
| 741 |
}; |
| 742 |
Container<4>::var_templ<int> inst; |
| 743 |
Container<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 ConstrainedMemberVarTemplate |
| 747 |
|
| 748 |
// These should not diagnose, where we were unintentionally doing so before by |
| 749 |
// checking trailing requires clause twice, yet not having the ability to the |
| 750 |
// 2nd time, since it was no longer a dependent variant. |
| 751 |
namespace InheritedFromPartialSpec { |
| 752 |
template<class C> |
| 753 |
constexpr bool Check = true; |
| 754 |
|
| 755 |
template<typename T> |
| 756 |
struct 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 |
|
| 766 |
template<> |
| 767 |
struct Foo<void> : Foo<int> { |
| 768 |
using Foo<int>::Foo; |
| 769 |
using Foo<int>::MemFunc; |
| 770 |
using Foo<int>::StaticMemFunc; |
| 771 |
}; |
| 772 |
|
| 773 |
void use() { |
| 774 |
Foo<void> F {1.1}; |
| 775 |
F.MemFunc(1.1); |
| 776 |
Foo<void>::StaticMemFunc(1.1); |
| 777 |
} |
| 778 |
|
| 779 |
template<typename T> |
| 780 |
struct counted_iterator { |
| 781 |
constexpr auto operator->() const noexcept requires false { |
| 782 |
return T::Invalid; |
| 783 |
}; |
| 784 |
}; |
| 785 |
|
| 786 |
template<class _Ip> |
| 787 |
concept __has_member_pointer = requires { typename _Ip::pointer; }; |
| 788 |
|
| 789 |
template<class> |
| 790 |
struct __iterator_traits_member_pointer_or_arrow_or_void { using type = void; }; |
| 791 |
template<__has_member_pointer _Ip> |
| 792 |
struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { using type = typename _Ip::pointer; }; |
| 793 |
|
| 794 |
template<class _Ip> |
| 795 |
requires requires(_Ip& __i) { __i.operator->(); } && (!__has_member_pointer<_Ip>) |
| 796 |
struct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { |
| 797 |
using type = decltype(declval<_Ip&>().operator->()); |
| 798 |
}; |
| 799 |
|
| 800 |
|
| 801 |
void use2() { |
| 802 |
__iterator_traits_member_pointer_or_arrow_or_void<counted_iterator<int>> f; |
| 803 |
} |
| 804 |
}// namespace InheritedFromPartialSpec |
| 805 |
|
| 806 |
namespace GH48182 { |
| 807 |
template<typename, typename..., typename = int> // expected-error{{template parameter pack must be the last template parameter}} |
| 808 |
concept invalid = true; |
| 809 |
|
| 810 |
template<typename> requires invalid<int> // expected-error{{use of undeclared identifier 'invalid'}} |
| 811 |
no errors are printed |
| 812 |
; |
| 813 |
|
| 814 |
static_assert(invalid<int> also here ; // expected-error{{use of undeclared identifier 'invalid'}} |
| 815 |
|
| 816 |
int 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 GH48182 |
| 822 |
|
| 823 |
namespace GH61777 { |
| 824 |
template<class T> concept C = sizeof(T) == 4; // #61777_C |
| 825 |
template<class T, class U> concept C2 = sizeof(T) == sizeof(U); //#61777_C2 |
| 826 |
|
| 827 |
template<class T> |
| 828 |
struct Parent { |
| 829 |
template<class, C auto> struct TakesUnary { static const int i = 0 ; }; // #UNARY |
| 830 |
template<class, C2<T> auto> struct TakesBinary { static const int i = 0 ; }; //#BINARY |
| 831 |
}; |
| 832 |
|
| 833 |
static_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}} |
| 837 |
static_assert(Parent<void>::TakesUnary<int, 0uLL>::i == 0); |
| 838 |
|
| 839 |
static_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}} |
| 843 |
static_assert(Parent<int>::TakesBinary<int, 0ULL>::i == 0); |
| 844 |
} |
| 845 |
|
| 846 |
namespace TemplateInsideNonTemplateClass { |
| 847 |
template<typename T, typename U> concept C = true; |
| 848 |
|
| 849 |
template<typename T> auto L = []<C<T> U>() {}; |
| 850 |
|
| 851 |
struct Q { |
| 852 |
template<C<int> U> friend constexpr auto decltype(L<int>)::operator()() const; |
| 853 |
}; |
| 854 |
|
| 855 |
template <class T> |
| 856 |
concept C1 = false; |
| 857 |
|
| 858 |
struct Foo { |
| 859 |
template <typename> |
| 860 |
struct Bar {}; |
| 861 |
|
| 862 |
template <typename T> |
| 863 |
requires(C1<T>) |
| 864 |
struct Bar<T>; |
| 865 |
}; |
| 866 |
|
| 867 |
Foo::Bar<int> BarInstance; |
| 868 |
} // namespace TemplateInsideNonTemplateClass |
| 869 |
|
| 870 |
namespace GH61959 { |
| 871 |
template <typename T0> |
| 872 |
concept C = (sizeof(T0) >= 4); |
| 873 |
|
| 874 |
template<typename...> |
| 875 |
struct Orig { }; |
| 876 |
|
| 877 |
template<typename T> |
| 878 |
struct Orig<T> { |
| 879 |
template<typename> requires C<T> |
| 880 |
void f() { } |
| 881 |
|
| 882 |
template<typename> requires true |
| 883 |
void f() { } |
| 884 |
}; |
| 885 |
|
| 886 |
template <typename...> struct Mod {}; |
| 887 |
|
| 888 |
template <typename T1, typename T2> |
| 889 |
struct 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 |
|
| 897 |
static_assert(Mod<int, char>::f<double>() == 1); |
| 898 |
static_assert(Mod<char, int>::f<double>() == 2); |
| 899 |
|
| 900 |
template<typename T> |
| 901 |
struct 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 |
|
| 914 |
void bar() { |
| 915 |
Outer<int>::Inner<float> I; |
| 916 |
I.foo<char>(); |
| 917 |
} |
| 918 |
} // namespace GH61959 |
| 919 |
|
| 920 |
|
| 921 |
namespace TemplateInsideTemplateInsideTemplate { |
| 922 |
template<typename T> |
| 923 |
concept C1 = false; |
| 924 |
|
| 925 |
template <unsigned I0> |
| 926 |
struct 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 |
|
| 942 |
static_assert(W0<0>::W1<1>::F<int>::value == 1); |
| 943 |
} // TemplateInsideTemplateInsideTemplate |
| 944 |
|
| 945 |
|
| 946 |
namespace GH63181 { |
| 947 |
|
| 948 |
template<auto N, class T> void f() { |
| 949 |
auto l = []() requires N { }; // expected-note 2{{candidate function not viable: constraints not satisfied}} \ |
| 950 |
// expected-note 2{{because 'false' evaluated to false}} |
| 951 |
|
| 952 |
l(); |
| 953 |
// expected-error@-1 {{no matching function for call to object of type}} |
| 954 |
void(*ptr)() = l; |
| 955 |
// expected-error-re@-1 {{no viable conversion from '(lambda {{.*}})' to 'void (*)()'}} |
| 956 |
} |
| 957 |
|
| 958 |
template void f<false, int>(); // expected-note {{in instantiation of function template specialization 'GH63181::f<false, int>' requested here}} |
| 959 |
template void f<true, int>(); |
| 960 |
|
| 961 |
template<class T> concept C = __is_same(T, int); // expected-note{{because '__is_same(char, int)' evaluated to false}} |
| 962 |
|
| 963 |
template<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 |
|
| 970 |
template void f<int, int, int>(); |
| 971 |
template void f<int, int, char>(); |
| 972 |
//expected-note@-1{{in instantiation of function template specialization 'GH63181::f<int, int, char>' requested here}} |
| 973 |
|
| 974 |
|
| 975 |
template <typename T, bool IsTrue> |
| 976 |
concept Test = IsTrue; // expected-note 2{{because 'false' evaluated to false}} |
| 977 |
|
| 978 |
template <typename T, bool IsTrue> |
| 979 |
void 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 |
|
| 988 |
void 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 |
|
| 995 |
namespace GH54678 { |
| 996 |
template<class> |
| 997 |
concept True = true; |
| 998 |
|
| 999 |
template<class> |
| 1000 |
concept False = false; // expected-note 9 {{'false' evaluated to false}} |
| 1001 |
|
| 1002 |
template<class> |
| 1003 |
concept Irrelevant = false; |
| 1004 |
|
| 1005 |
template <typename T> |
| 1006 |
concept ErrorRequires = requires(ErrorRequires auto x) { x; }; //#GH54678-ill-formed-concept |
| 1007 |
// 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 |
|
| 1011 |
template<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 |
|
| 1015 |
template<class T> void aaa(T t) // expected-note {{candidate template ignored: constraints not satisfied}} |
| 1016 |
requires (False<T> || False<T>) || False<T> {} // expected-note 3 {{'int' does not satisfy 'False'}} |
| 1017 |
template<class T> void bbb(T t) // expected-note {{candidate template ignored: constraints not satisfied}} |
| 1018 |
requires (False<T> || False<T>) && True<T> {} // expected-note 2 {{'long' does not satisfy 'False'}} |
| 1019 |
template<class T> void ccc(T t) // expected-note {{candidate template ignored: constraints not satisfied}} |
| 1020 |
requires (True<T> || Irrelevant<T>) && False<T> {} // expected-note {{'unsigned long' does not satisfy 'False'}} |
| 1021 |
template<class T> void ddd(T t) // expected-note {{candidate template ignored: constraints not satisfied}} |
| 1022 |
requires (Irrelevant<T> || True<T>) && False<T> {} // expected-note {{'int' does not satisfy 'False'}} |
| 1023 |
template<class T> void eee(T t) // expected-note {{candidate template ignored: constraints not satisfied}} |
| 1024 |
requires (Irrelevant<T> || Irrelevant<T> || True<T>) && False<T> {} // expected-note {{'long' does not satisfy 'False'}} |
| 1025 |
|
| 1026 |
template<class T> void fff(T t) // expected-note {{candidate template ignored: constraints not satisfied}} |
| 1027 |
requires((ErrorRequires<T> || False<T> || True<T>) && False<T>) {} // expected-note {{because 'unsigned long' does not satisfy 'False'}} |
| 1028 |
void 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 |
|
| 1038 |
namespace 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_END |
| 1048 |
}; |
| 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 |
|
| 1054 |
namespace GH66938 { |
| 1055 |
template <class> |
| 1056 |
concept True = true; |
| 1057 |
|
| 1058 |
template <class> |
| 1059 |
concept False = false; |
| 1060 |
|
| 1061 |
template <class T> |
| 1062 |
void 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 |
|
| 1067 |
void test() { cand(42); } |
| 1068 |
} |
| 1069 |
|
| 1070 |
namespace GH63837 { |
| 1071 |
|
| 1072 |
template<class> concept IsFoo = true; |
| 1073 |
|
| 1074 |
template<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 |
|
| 1085 |
template void Struct<void>::foo<>(); |
| 1086 |
template void Struct<void>::bar<>(); |
| 1087 |
template int Struct<void>::field<1, 2>; |
| 1088 |
|
| 1089 |
} |
| 1090 |
|
| 1091 |
namespace GH64808 { |
| 1092 |
|
| 1093 |
template <class T> struct basic_sender { |
| 1094 |
T func; |
| 1095 |
basic_sender(T) : func(T()) {} |
| 1096 |
}; |
| 1097 |
|
| 1098 |
auto a = basic_sender{[](auto... __captures) { |
| 1099 |
return []() // #note-a-1 |
| 1100 |
requires((__captures, ...), false) // #note-a-2 |
| 1101 |
{}; |
| 1102 |
}()}; |
| 1103 |
|
| 1104 |
auto b = basic_sender{[](auto... __captures) { |
| 1105 |
return []() |
| 1106 |
requires([](int, double) { return true; }(decltype(__captures)()...)) |
| 1107 |
{}; |
| 1108 |
}(1, 2.33)}; |
| 1109 |
|
| 1110 |
void 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 GH64808 |
| 1119 |
|
| 1120 |
namespace GH86757_1 { |
| 1121 |
template <typename...> concept b = false; |
| 1122 |
template <typename> concept c = b<>; |
| 1123 |
template <typename d> concept f = c< d >; |
| 1124 |
template <f> struct e; // expected-note {{}} |
| 1125 |
template <f d> struct e<d>; // expected-error {{class template partial specialization is not more specialized than the primary template}} |
| 1126 |
} |
| 1127 |
|
| 1128 |
|
| 1129 |
namespace constrained_variadic { |
| 1130 |
template <typename T = int> |
| 1131 |
struct 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 |
|
| 1142 |
int 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 |
|
| 1150 |
namespace GH109780 { |
| 1151 |
|
| 1152 |
template <typename T> |
| 1153 |
concept Concept; // expected-error {{expected '='}} |
| 1154 |
|
| 1155 |
bool val = Concept<int>; |
| 1156 |
|
| 1157 |
template <typename T> |
| 1158 |
concept C = invalid; // expected-error {{use of undeclared identifier 'invalid'}} |
| 1159 |
|
| 1160 |
bool val2 = C<int>; |
| 1161 |
|
| 1162 |
} // namespace GH109780 |
| 1163 |
|
| 1164 |
namespace GH121980 { |
| 1165 |
|
| 1166 |
template <class> |
| 1167 |
concept has_member_difference_type; // expected-error {{expected '='}} |
| 1168 |
|
| 1169 |
template <has_member_difference_type> struct incrementable_traits; // expected-note {{declared here}} |
| 1170 |
|
| 1171 |
template <has_member_difference_type Tp> |
| 1172 |
struct incrementable_traits<Tp>; // expected-error {{not more specialized than the primary}} |
| 1173 |
|
| 1174 |
} |
| 1175 |
|
| 1176 |
namespace InjectedClassNameType { |
| 1177 |
|
| 1178 |
template <class, class _Err> class expected { |
| 1179 |
public: |
| 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 |
|
| 1193 |
bool test_val_types() { |
| 1194 |
return expected<void, int>() == 1; |
| 1195 |
} |
| 1196 |
|
| 1197 |
} |
| 1198 |
|
| 1199 |
namespace CWG2369_Regression { |
| 1200 |
|
| 1201 |
enum class KindEnum { |
| 1202 |
Unknown = 0, |
| 1203 |
Foo = 1, |
| 1204 |
}; |
| 1205 |
|
| 1206 |
template <typename T> |
| 1207 |
concept KnownKind = T::kind() != KindEnum::Unknown; |
| 1208 |
|
| 1209 |
template <KnownKind T> struct KnownType; |
| 1210 |
|
| 1211 |
struct 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 |
|
| 1224 |
template <KnownKind T> struct KnownType { |
| 1225 |
static constexpr KindEnum kind() { return KindEnum::Foo; } |
| 1226 |
}; |
| 1227 |
|
| 1228 |
} |
| 1229 |
|
| 1230 |
namespace CWG2369_Regression_2 { |
| 1231 |
|
| 1232 |
template <typename T> |
| 1233 |
concept HasFastPropertyForAttribute = |
| 1234 |
requires(T element, int name) { element.propertyForAttribute(name); }; |
| 1235 |
|
| 1236 |
template <typename OwnerType> |
| 1237 |
struct SVGPropertyOwnerRegistry { |
| 1238 |
static int fastAnimatedPropertyLookup() { |
| 1239 |
static_assert (HasFastPropertyForAttribute<OwnerType>); |
| 1240 |
return 1; |
| 1241 |
} |
| 1242 |
}; |
| 1243 |
|
| 1244 |
class SVGCircleElement { |
| 1245 |
friend SVGPropertyOwnerRegistry<SVGCircleElement>; |
| 1246 |
void propertyForAttribute(int); |
| 1247 |
}; |
| 1248 |
|
| 1249 |
int i = SVGPropertyOwnerRegistry<SVGCircleElement>::fastAnimatedPropertyLookup(); |
| 1250 |
|
| 1251 |
} |
| 1252 |
|
| 1253 |
namespace GH61824 { |
| 1254 |
|
| 1255 |
template<typename T, typename U = typename T::type> // #T_Type |
| 1256 |
concept C = true; |
| 1257 |
|
| 1258 |
constexpr bool f(C auto) { // #GH61824_f |
| 1259 |
return true; |
| 1260 |
} |
| 1261 |
|
| 1262 |
C 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 |
|
| 1266 |
static_assert(f(0)); |
| 1267 |
|
| 1268 |
} |
| 1269 |
|
| 1270 |
namespace GH149986 { |
| 1271 |
template <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 |
} |
| 1277 |
namespace GH61811{ |
| 1278 |
template <class T> struct A { static const int x = 42; }; |
| 1279 |
template <class Ta> concept A42 = A<Ta>::x == 42; |
| 1280 |
template <class Tv> concept Void = __is_same_as(Tv, void); |
| 1281 |
template <class Tb, class Ub> concept A42b = Void<Tb> || A42<Ub>; |
| 1282 |
template <class Tc> concept R42c = A42b<Tc, Tc&>; |
| 1283 |
static_assert (R42c<void>); |
| 1284 |
} |
| 1285 |
|
| 1286 |
namespace parameter_mapping_regressions { |
| 1287 |
|
| 1288 |
namespace case1 { |
| 1289 |
|
| 1290 |
template <template <class> class> using __meval = struct __q; |
| 1291 |
template <template <class> class _Tp> |
| 1292 |
concept __mvalid = requires { typename __meval<_Tp>; }; |
| 1293 |
template <class _Fn> |
| 1294 |
concept __minvocable = __mvalid<_Fn::template __f>; |
| 1295 |
template <class...> struct __mdefer_; |
| 1296 |
template <class _Fn, class... _Args> |
| 1297 |
requires __minvocable<_Fn> |
| 1298 |
struct __mdefer_<_Fn, _Args...> {}; |
| 1299 |
template <class = __q> struct __mtransform { |
| 1300 |
template <class> using __f = int; |
| 1301 |
}; |
| 1302 |
struct __completion_domain_or_none_ : __mdefer_<__mtransform<>> {}; |
| 1303 |
|
| 1304 |
} |
| 1305 |
|
| 1306 |
namespace case2 { |
| 1307 |
|
| 1308 |
template<auto& Q, class P> concept C = Q.template operator()<P>(); |
| 1309 |
template<class P> concept E = C<[]<class Ty>{ return false; }, P>; |
| 1310 |
static_assert(!E<int>); |
| 1311 |
|
| 1312 |
} |
| 1313 |
|
| 1314 |
|
| 1315 |
namespace case3 { |
| 1316 |
template <class> constexpr bool is_move_constructible_v = false; |
| 1317 |
|
| 1318 |
template <class _Tp> |
| 1319 |
concept __cpp17_move_constructible = is_move_constructible_v<_Tp>; // #is_move_constructible_v |
| 1320 |
|
| 1321 |
template <class _Tp> |
| 1322 |
concept __cpp17_copy_constructible = __cpp17_move_constructible<_Tp>; // #__cpp17_move_constructible |
| 1323 |
|
| 1324 |
template <class _Iter> |
| 1325 |
concept __cpp17_iterator = __cpp17_copy_constructible<_Iter>; // #__cpp17_copy_constructible |
| 1326 |
|
| 1327 |
struct not_move_constructible {}; |
| 1328 |
static_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 |
|
| 1336 |
namespace case4 { |
| 1337 |
|
| 1338 |
template<bool b> |
| 1339 |
concept bool_ = b; |
| 1340 |
|
| 1341 |
template<typename... Ts> |
| 1342 |
concept unary = bool_<sizeof...(Ts) == 1>; |
| 1343 |
|
| 1344 |
static_assert(!unary<>); |
| 1345 |
static_assert(unary<void>); |
| 1346 |
|
| 1347 |
} |
| 1348 |
|
| 1349 |
namespace case5 { |
| 1350 |
|
| 1351 |
template<int size> |
| 1352 |
concept true1 = size == size; |
| 1353 |
|
| 1354 |
template<typename... Ts> |
| 1355 |
concept true2 = true1<sizeof...(Ts)>; |
| 1356 |
|
| 1357 |
template<typename... Ts> |
| 1358 |
concept true3 = true2<Ts...>; |
| 1359 |
|
| 1360 |
static_assert(true3<void>); |
| 1361 |
|
| 1362 |
} |
| 1363 |
|
| 1364 |
namespace case6 { |
| 1365 |
|
| 1366 |
namespace std { |
| 1367 |
template <int __v> |
| 1368 |
struct integral_constant { |
| 1369 |
static const int value = __v; |
| 1370 |
}; |
| 1371 |
|
| 1372 |
template <class _Tp, class... _Args> |
| 1373 |
constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...); |
| 1374 |
|
| 1375 |
template <class _From, class _To> |
| 1376 |
constexpr bool is_convertible_v = __is_convertible(_From, _To); |
| 1377 |
|
| 1378 |
template <class> |
| 1379 |
struct tuple_size; |
| 1380 |
|
| 1381 |
template <class _Tp> |
| 1382 |
constexpr decltype(sizeof(int)) tuple_size_v = tuple_size<_Tp>::value; |
| 1383 |
} // namespace std |
| 1384 |
|
| 1385 |
template <int N, int X> |
| 1386 |
concept FixedExtentConstructibleFromExtent = X == N; |
| 1387 |
|
| 1388 |
template <int Extent> |
| 1389 |
struct 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 |
|
| 1396 |
template <class, int> |
| 1397 |
struct array {}; |
| 1398 |
|
| 1399 |
template <class _Tp, decltype(sizeof(int)) _Size> |
| 1400 |
struct std::tuple_size<array<_Tp, _Size>> : integral_constant<_Size> {}; |
| 1401 |
|
| 1402 |
static_assert(std::is_convertible_v<array<int, 3>, span<3>>); |
| 1403 |
static_assert(!std::is_constructible_v<span<4>, array<int, 3>>); |
| 1404 |
|
| 1405 |
} |
| 1406 |
|
| 1407 |
namespace case7 { |
| 1408 |
|
| 1409 |
template <class _Tp, class _Up> |
| 1410 |
concept __same_as_impl = __is_same(_Tp, _Up); |
| 1411 |
template <class _Tp, class _Up> |
| 1412 |
concept same_as = __same_as_impl<_Tp, _Up>; |
| 1413 |
template <typename> |
| 1414 |
concept IsEntitySpec = |
| 1415 |
requires { requires same_as<void, void>; }; |
| 1416 |
|
| 1417 |
} |
| 1418 |
|
| 1419 |
namespace case8 { |
| 1420 |
|
| 1421 |
template <class T> |
| 1422 |
struct type_identity { |
| 1423 |
using type = T; |
| 1424 |
}; |
| 1425 |
|
| 1426 |
template <typename Inner> |
| 1427 |
struct Cat {}; |
| 1428 |
|
| 1429 |
template <typename T> |
| 1430 |
concept CatConcept = requires { |
| 1431 |
[]<class Inner>(type_identity<Cat<Inner>>) {}(type_identity<T>{}); |
| 1432 |
}; |
| 1433 |
|
| 1434 |
template <typename Dummy> |
| 1435 |
struct Feeder { |
| 1436 |
template <CatConcept Dummy2> |
| 1437 |
void feed() noexcept {} |
| 1438 |
}; |
| 1439 |
|
| 1440 |
void main() { Feeder<int>{}.feed<Cat<int>>(); } |
| 1441 |
|
| 1442 |
} |
| 1443 |
|
| 1444 |
namespace case9 { |
| 1445 |
|
| 1446 |
template <typename> |
| 1447 |
concept a = requires { requires true; }; |
| 1448 |
template <typename T> |
| 1449 |
concept b = a<typename T::EntitySpec>; |
| 1450 |
template <typename T> |
| 1451 |
concept c = requires { b<T>; }; |
| 1452 |
template <typename T> |
| 1453 |
requires c<T> |
| 1454 |
struct s; |
| 1455 |
template <typename> constexpr bool f() { return true; } |
| 1456 |
template <typename T> constexpr bool d = f<T>(); |
| 1457 |
struct s2; |
| 1458 |
static_assert(d<s<s2>>); |
| 1459 |
|
| 1460 |
} |
| 1461 |
|
| 1462 |
} |
| 1463 |
|
| 1464 |
namespace GH162125 { |
| 1465 |
template<typename, int size> |
| 1466 |
concept true_int = (size, true); |
| 1467 |
|
| 1468 |
template<typename, typename... Ts> |
| 1469 |
concept true_types = true_int<void, sizeof...(Ts)>; |
| 1470 |
|
| 1471 |
template<typename, typename... Ts> |
| 1472 |
concept true_types2 = true_int<void, Ts...[0]{1}>; // cxx20-warning {{pack indexing is a C++2c extension}} |
| 1473 |
|
| 1474 |
template<typename... Ts> |
| 1475 |
struct s { |
| 1476 |
template<typename T> requires true_types<T, Ts...> && true_types2<T, Ts...> |
| 1477 |
static void f(T); |
| 1478 |
}; |
| 1479 |
void(*test)(int) = &s<bool>::f<int>; |
| 1480 |
} |
| 1481 |
|
| 1482 |
namespace GH162125_reversed { |
| 1483 |
template<int size, typename> |
| 1484 |
concept true_int = (size, true); |
| 1485 |
|
| 1486 |
template<typename, typename... Ts> |
| 1487 |
concept true_types = true_int<sizeof...(Ts), void>; |
| 1488 |
|
| 1489 |
template<typename, typename... Ts> |
| 1490 |
concept true_types2 = true_int<Ts...[0]{1}, void>; // cxx20-warning {{pack indexing is a C++2c extension}} |
| 1491 |
|
| 1492 |
template<typename... Ts> |
| 1493 |
struct s { |
| 1494 |
template<typename T> requires true_types<T, Ts...> && true_types2<T, Ts...> |
| 1495 |
static void f(T); |
| 1496 |
}; |
| 1497 |
|
| 1498 |
void(*test)(int) = &s<bool>::f<int>; |
| 1499 |
} |
| 1500 |
namespace GH51246 { |
| 1501 |
void f(); // expected-note {{possible target for call}} |
| 1502 |
void f(int); // expected-note {{possible target for call}} |
| 1503 |
void g(); |
| 1504 |
static_assert(requires { f; }); // expected-error {{reference to overloaded function could not be resolved}} |
| 1505 |
static_assert(requires { g; }); |
| 1506 |
struct 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 GH51246 |
| 1520 |
|
| 1521 |
|
| 1522 |
namespace GH97753 { |
| 1523 |
|
| 1524 |
void f(); // expected-note {{possible target for call}} |
| 1525 |
void f(int); // expected-note {{possible target for call}} |
| 1526 |
|
| 1527 |
template<typename T> |
| 1528 |
concept C = sizeof(T) == 42; |
| 1529 |
|
| 1530 |
static_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 |
|
| 1535 |
namespace GH162092 { |
| 1536 |
|
| 1537 |
template <typename T> |
| 1538 |
struct vector; |
| 1539 |
|
| 1540 |
template <typename T, typename U> |
| 1541 |
concept C = __is_same_as(T, U); |
| 1542 |
|
| 1543 |
template<class T, auto Cpt> |
| 1544 |
concept generic_range_value = requires { |
| 1545 |
Cpt.template operator()<int>(); |
| 1546 |
}; |
| 1547 |
|
| 1548 |
|
| 1549 |
template<generic_range_value<[]< |
| 1550 |
C<int> |
| 1551 |
>() {}> T> |
| 1552 |
void x() {} |
| 1553 |
|
| 1554 |
void foo() { |
| 1555 |
x<vector<int>>(); |
| 1556 |
} |
| 1557 |
|
| 1558 |
} |
| 1559 |
|
| 1560 |
namespace 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 GH162770 |
| 1576 |
|
| 1577 |
namespace GH164750 { |
| 1578 |
|
| 1579 |
template <typename> |
| 1580 |
struct a; |
| 1581 |
template <typename> |
| 1582 |
struct b; |
| 1583 |
|
| 1584 |
template <template <typename> typename c, typename d, typename> |
| 1585 |
concept e = !__is_convertible_to(c<d>*, b<d>*); |
| 1586 |
|
| 1587 |
template <typename...> |
| 1588 |
struct f; |
| 1589 |
template <typename g, typename... h> |
| 1590 |
struct f<g, h...> { |
| 1591 |
g i; |
| 1592 |
}; |
| 1593 |
|
| 1594 |
template <typename, typename> |
| 1595 |
struct u; |
| 1596 |
template <typename j, template <typename> typename k, typename l> |
| 1597 |
requires e<k, j, l> |
| 1598 |
struct u<const k<j>*, l> { |
| 1599 |
u(const a<j>*); |
| 1600 |
}; |
| 1601 |
template <typename j, template <typename> typename k, typename l> |
| 1602 |
struct u<const k<j>*, l> { |
| 1603 |
u(const b<j>*); |
| 1604 |
}; |
| 1605 |
|
| 1606 |
template <typename> |
| 1607 |
struct m; |
| 1608 |
template <typename n, typename... o> |
| 1609 |
struct m<n (*)(o...)> { |
| 1610 |
template <template <typename> typename j> |
| 1611 |
using p = j<o...>; |
| 1612 |
}; |
| 1613 |
|
| 1614 |
template <typename q, typename r> |
| 1615 |
struct 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 |
}; |
| 1624 |
template <typename w, typename... t> |
| 1625 |
void fn1(w, t... p2) { |
| 1626 |
s<w, t...>(p2...); |
| 1627 |
} |
| 1628 |
int* fn2(int) { return nullptr; } |
| 1629 |
void fn3() { |
| 1630 |
fn1(fn2, static_cast<const a<int>*>(nullptr)); |
| 1631 |
fn1(fn2, static_cast<const b<int>*>(nullptr)); |
| 1632 |
} |
| 1633 |
|
| 1634 |
} |
| 1635 |
|
| 1636 |
namespace GH165238 { |
| 1637 |
|
| 1638 |
namespace std { |
| 1639 |
template <typename, typename _Tp> |
| 1640 |
concept output_iterator = requires(_Tp __t) { __t; }; |
| 1641 |
template <typename _Out> struct basic_format_context { |
| 1642 |
static_assert(output_iterator<_Out, int>); |
| 1643 |
using char_type = _Out; |
| 1644 |
}; |
| 1645 |
template <typename> class basic_format_parse_context; |
| 1646 |
template <typename, typename _Context, typename _Formatter, |
| 1647 |
typename = basic_format_parse_context<typename _Context::char_type>> |
| 1648 |
concept __parsable_with = requires(_Formatter __f) { __f; }; |
| 1649 |
template <typename _Tp, typename _CharT, |
| 1650 |
typename _Context = basic_format_context<_CharT>> |
| 1651 |
concept __formattable_impl = __parsable_with<_Tp, _Context, _Context>; |
| 1652 |
template <typename _Tp, typename _CharT> |
| 1653 |
concept formattable = __formattable_impl<_Tp, _CharT>; |
| 1654 |
} // namespace std |
| 1655 |
struct { |
| 1656 |
void operator()(std::formattable<char> auto); |
| 1657 |
} call; |
| 1658 |
void foo() { call(""); } |
| 1659 |
|
| 1660 |
} |
| 1661 |
|
| 1662 |
namespace GH186624 { |
| 1663 |
|
| 1664 |
template <class T> |
| 1665 |
concept C = __is_unsigned(T); |
| 1666 |
|
| 1667 |
template <C T> |
| 1668 |
struct encoder_interface {}; |
| 1669 |
|
| 1670 |
template <template <C> class CodecInterface, C T> |
| 1671 |
CodecInterface<T>* create_codec() { |
| 1672 |
return nullptr; |
| 1673 |
} |
| 1674 |
|
| 1675 |
encoder_interface<unsigned>* create_encoder() { |
| 1676 |
return create_codec<encoder_interface, unsigned>(); |
| 1677 |
} |
| 1678 |
|
| 1679 |
} |
| 1680 |
|
| 1681 |
namespace GH170856 { |
| 1682 |
|
| 1683 |
template <unsigned N, unsigned M> struct symbol_text { |
| 1684 |
consteval symbol_text(const char txt[]) {} |
| 1685 |
}; |
| 1686 |
template <unsigned N> symbol_text(const char (&)[N]) -> symbol_text<1, 1>; |
| 1687 |
struct quantity_spec_interface_base {}; |
| 1688 |
template <symbol_text, auto...> struct named_unit; |
| 1689 |
struct quantity_spec_interface : quantity_spec_interface_base {}; |
| 1690 |
struct : quantity_spec_interface { |
| 1691 |
} thermodynamic_temperature; |
| 1692 |
|
| 1693 |
template <typename T> |
| 1694 |
concept QuantitySpec = __is_convertible(T*, quantity_spec_interface_base*); |
| 1695 |
template <typename, auto QS> |
| 1696 |
concept QuantitySpecOf = QuantitySpec<decltype(QS)>; |
| 1697 |
template <typename T, auto QS> |
| 1698 |
concept PointOriginFor = QuantitySpecOf<decltype(QS), T::_quantity_spec_>; |
| 1699 |
|
| 1700 |
template <symbol_text Symbol, auto QS, auto PO> |
| 1701 |
struct named_unit<Symbol, QS, PO> { |
| 1702 |
static constexpr auto _point_origin_ = PO; |
| 1703 |
}; |
| 1704 |
template <auto QS> struct absolute_point_origin { |
| 1705 |
static constexpr auto _quantity_spec_ = QS; |
| 1706 |
}; |
| 1707 |
template <auto> struct relative_point_origin {}; |
| 1708 |
template <class R> |
| 1709 |
consteval PointOriginFor<R{}> auto default_point_origin(R) { |
| 1710 |
return R{}._point_origin_; |
| 1711 |
} |
| 1712 |
template <auto> class quantity_point; |
| 1713 |
template <class R> struct point_ { |
| 1714 |
quantity_point<default_point_origin(R{})> operator0(); |
| 1715 |
}; |
| 1716 |
template <auto R> point_<decltype(R)> point; |
| 1717 |
struct absolute_zero : absolute_point_origin<thermodynamic_temperature> { |
| 1718 |
} absolute_zero; |
| 1719 |
auto zeroth_kelvin = absolute_zero; |
| 1720 |
struct : named_unit<"", thermodynamic_temperature, zeroth_kelvin> { |
| 1721 |
} kelvin; |
| 1722 |
struct ice_point : relative_point_origin<point<kelvin>> {}; |
| 1723 |
|
| 1724 |
} |
| 1725 |
|
| 1726 |
namespace GH182344 { |
| 1727 |
|
| 1728 |
template <typename T> |
| 1729 |
requires true |
| 1730 |
void f() {} |
| 1731 |
|
| 1732 |
template <typename T> |
| 1733 |
requires false |
| 1734 |
void f() = delete; |
| 1735 |
|
| 1736 |
struct Bar {}; |
| 1737 |
|
| 1738 |
template <typename> using Foo = Bar; |
| 1739 |
|
| 1740 |
template <int T> |
| 1741 |
requires true |
| 1742 |
void f2() {} |
| 1743 |
|
| 1744 |
template <int T> |
| 1745 |
requires false |
| 1746 |
void f2() = delete; |
| 1747 |
|
| 1748 |
template <int> constexpr auto Value = 1; |
| 1749 |
|
| 1750 |
template <template <typename> class> using FooTemp = Bar; |
| 1751 |
|
| 1752 |
template <typename T, int N, template <typename> class C> void use() { |
| 1753 |
f<Foo<T>>(); |
| 1754 |
f2<Value<N>>(); |
| 1755 |
f<FooTemp<C>>(); |
| 1756 |
} |
| 1757 |
|
| 1758 |
} |
| 1759 |
|
| 1760 |
namespace instantiation_dependent { |
| 1761 |
template <class T> concept C = sizeof(T) >= 1; |
| 1762 |
template <class U> using X = int; |
| 1763 |
template <class V> requires C<X<V&>> struct Y {}; |
| 1764 |
Y<void> y; |
| 1765 |
// expected-error@-1 {{constraints not satisfied for class template 'Y' [with V = void]}} |
| 1766 |
// expected-note@-3 {{because substituted constraint expression is ill-formed: cannot form a reference to 'void'}} |
| 1767 |
} // namespace instantiation_dependent |
| 1768 |
|
| 1769 |
namespace GH174667 { |
| 1770 |
|
| 1771 |
template<class T, class, class U> |
| 1772 |
concept C = requires{ requires U(T(1)); }; |
| 1773 |
|
| 1774 |
template<C<void, bool> T> int f(); |
| 1775 |
void main() { f<int>(); } |
| 1776 |
|
| 1777 |
} |