84 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -x c++ %s -Wno-unused-value -verify2 3template <typename... Args> requires ((sizeof(Args) == 1), ...)4// expected-note@-1 {{because '(sizeof(int) == 1) , (sizeof(char) == 1) , (sizeof(int) == 1)' evaluated to false}}5void f1(Args&&... args) { }6// expected-note@-1 {{candidate template ignored: constraints not satisfied [with Args = <int, char, int>]}}7 8using f11 = decltype(f1('a'));9using f12 = decltype(f1(1, 'b'));10using f13 = decltype(f1(1, 'b', 2));11// expected-error@-1 {{no matching function for call to 'f1'}}12 13template <typename... Args>14void f2(Args&&... args) requires ((sizeof(args) == 1), ...) { }15// expected-note@-1 {{candidate template ignored: constraints not satisfied [with Args = <int, char, int>]}}16// expected-note@-2 {{because '(sizeof (args) == 1) , (sizeof (args) == 1) , (sizeof (args) == 1)' evaluated to false}}17 18using f21 = decltype(f2('a'));19using f22 = decltype(f2(1, 'b'));20using f23 = decltype(f2(1, 'b', 2));21// expected-error@-1 {{no matching function for call to 'f2'}}22 23template <typename... Args> requires ((sizeof(Args) == 1), ...)24// expected-note@-1 {{because '(sizeof(int) == 1) , (sizeof(char) == 1) , (sizeof(int) == 1)' evaluated to false}}25void f3(Args&&... args) requires ((sizeof(args) == 1), ...) { }26// expected-note@-1 {{candidate template ignored: constraints not satisfied [with Args = <int, char, int>]}}27 28using f31 = decltype(f3('a'));29using f32 = decltype(f3(1, 'b'));30using f33 = decltype(f3(1, 'b', 2));31// expected-error@-1 {{no matching function for call to 'f3'}}32 33template<typename T>34struct S {35 template<typename U>36 static constexpr auto f(U const index) requires(index, true) {37 return true;38 }39};40 41static_assert(S<void>::f(1));42 43// Similar to the 'S' test, but tries to use 'U' in the requires clause.44template <typename T2>45struct S1 {46 // expected-note@+3 {{candidate template ignored: constraints not satisfied [with U = int]}}47 // expected-note@+3 {{because substituted constraint expression is ill-formed: type 'int' cannot be used prior to '::' because it has no members}}48 template <typename U>49 static constexpr auto f(U const index)50 requires(U::foo)51 { return true; }52};53 54// expected-error@+1 {{no matching function for call to 'f'}}55static_assert(S1<void>::f(1));56 57constexpr auto value = 0;58 59template<typename T>60struct S2 {61 template<typename = void> requires(value, true)62 static constexpr auto f() requires(value, true) {63 }64};65 66static_assert((S2<int>::f(), true));67 68template<typename T>69struct S3 {70 template<typename... Args> requires true71 static constexpr void f(Args...) { }72};73 74static_assert((S3<int>::f(), true));75 76template<typename T>77struct S4 {78 template<typename>79 constexpr void foo() requires (decltype(this)(), true) { }80 constexpr void goo() requires (decltype(this)(), true) { }81};82 83static_assert((S4<int>{}.foo<int>(), S4<int>{}.goo(), true));84