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