107 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1z -triple=x86_64-linux-gnu2 3template <typename U, typename V>4struct S1 {5 static constexpr const bool value = false;6};7 8template <typename U, typename V>9inline constexpr bool global_inline_var = S1<U, V>::value;10 11template <typename T>12struct S2 {13 template <typename U, typename V>14 static inline constexpr bool var = global_inline_var<U, V>;15};16 17template <typename U, typename V>18inline constexpr bool constexpr_return_false() {19 return false;20}21 22template <typename U, typename V>23void foo() {24 static_assert(S1<U, V>::value);25 // expected-error@-1{{static assertion failed due to requirement 'S1<int, float>::value'}}26}27template void foo<int, float>();28// expected-note@-1{{in instantiation of function template specialization 'foo<int, float>' requested here}}29 30template <typename U, typename V>31void foo2() {32 static_assert(global_inline_var<U, V>);33 // expected-error@-1{{static assertion failed due to requirement 'global_inline_var<int, float>'}}34}35template void foo2<int, float>();36// expected-note@-1{{in instantiation of function template specialization 'foo2<int, float>' requested here}}37 38template <typename T, typename U, typename V>39void foo3() {40 static_assert(T::template var<U, V>);41 // expected-error@-1{{static assertion failed due to requirement 'S2<long>::var<int, float>'}}42}43template void foo3<S2<long>, int, float>();44// expected-note@-1{{in instantiation of function template specialization 'foo3<S2<long>, int, float>' requested here}}45 46template <typename T>47void foo4() {48 static_assert(S1<T[sizeof(T)], int[4]>::value, "");49 // expected-error@-1{{static assertion failed due to requirement 'S1<float[4], int[4]>::value'}}50};51template void foo4<float>();52// expected-note@-1{{in instantiation of function template specialization 'foo4<float>' requested here}}53 54 55template <typename U, typename V>56void foo5() {57 static_assert(!!(global_inline_var<U, V>));58 // expected-error@-1{{static assertion failed due to requirement '!!(global_inline_var<int, float>)'}}59}60template void foo5<int, float>();61// expected-note@-1{{in instantiation of function template specialization 'foo5<int, float>' requested here}}62 63struct ExampleTypes {64 explicit ExampleTypes(int);65 using T = int;66 using U = float;67};68 69template <class T>70struct X {71 int i = 0;72 int j = 0;73 constexpr operator bool() const { return false; }74};75 76template <class T>77void foo6() {78 static_assert(X<typename T::T>());79 // expected-error@-1{{static assertion failed due to requirement 'X<int>()'}}80 static_assert(X<typename T::T>{});81 // expected-error@-1{{static assertion failed due to requirement 'X<int>{}'}}82 static_assert(X<typename T::T>{1, 2});83 // expected-error@-1{{static assertion failed due to requirement 'X<int>{1, 2}'}}84 static_assert(X<typename T::T>({1, 2}));85 // expected-error@-1{{static assertion failed due to requirement 'X<int>({1, 2})'}}86 static_assert(typename T::T{0});87 // expected-error@-1{{static assertion failed due to requirement 'int{0}'}}88 static_assert(typename T::T(0));89 // expected-error@-1{{static assertion failed due to requirement 'int(0)'}}90 static_assert(sizeof(X<typename T::T>) == 0);91 // expected-error@-1{{static assertion failed due to requirement 'sizeof(X<int>) == 0'}} \92 // expected-note@-1 {{evaluates to '8 == 0'}}93 static_assert((const X<typename T::T> *)nullptr);94 // expected-error@-1{{static assertion failed due to requirement '(const X<int> *)nullptr'}}95 static_assert(static_cast<const X<typename T::T> *>(nullptr));96 // expected-error@-1{{static assertion failed due to requirement 'static_cast<const X<int> *>(nullptr)'}}97 static_assert((const X<typename T::T>[]){} == nullptr);98 // expected-error@-1{{static assertion failed due to requirement '(const X<int>[0]){} == nullptr'}}99 static_assert(sizeof(X<decltype(X<typename T::T>().X<typename T::T>::~X())>) == 0);100 // expected-error@-1{{static assertion failed due to requirement 'sizeof(X<void>) == 0'}} \101 // expected-note@-1 {{evaluates to '8 == 0'}}102 static_assert(constexpr_return_false<typename T::T, typename T::U>());103 // expected-error@-1{{static assertion failed due to requirement 'constexpr_return_false<int, float>()'}}104}105template void foo6<ExampleTypes>();106// expected-note@-1{{in instantiation of function template specialization 'foo6<ExampleTypes>' requested here}}107