blob: 7fff59e7f80ab8779f09f54ea79b212db45d7e32 [file] [log] [blame]
Clement Courbet9d432e02018-12-04 07:59:57 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1z -triple=x86_64-linux-gnu
2
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>
18void foo() {
19 static_assert(S1<U, V>::value);
20 // expected-error@-1{{static_assert failed due to requirement 'S1<int, float>::value'}}
21}
22template void foo<int, float>();
23// expected-note@-1{{in instantiation of function template specialization 'foo<int, float>' requested here}}
24
25template <typename U, typename V>
26void foo2() {
27 static_assert(global_inline_var<U, V>);
28 // expected-error@-1{{static_assert failed due to requirement 'global_inline_var<int, float>'}}
29}
30template void foo2<int, float>();
31// expected-note@-1{{in instantiation of function template specialization 'foo2<int, float>' requested here}}
32
33template <typename T, typename U, typename V>
34void foo3() {
35 static_assert(T::template var<U, V>);
36 // expected-error@-1{{static_assert failed due to requirement 'S2<long>::var<int, float>'}}
37}
38template void foo3<S2<long>, int, float>();
39// expected-note@-1{{in instantiation of function template specialization 'foo3<S2<long>, int, float>' requested here}}
40
41template <typename T>
42void foo4() {
43 static_assert(S1<T[sizeof(T)], int[4]>::value, "");
44 // expected-error@-1{{static_assert failed due to requirement 'S1<float [4], int [4]>::value'}}
45};
46template void foo4<float>();
47// expected-note@-1{{in instantiation of function template specialization 'foo4<float>' requested here}}
Clement Courbetf44c6f42018-12-11 08:39:11 +000048
49
50template <typename U, typename V>
51void foo5() {
52 static_assert(!!(global_inline_var<U, V>));
53 // expected-error@-1{{static_assert failed due to requirement '!!(global_inline_var<int, float>)'}}
54}
55template void foo5<int, float>();
56// expected-note@-1{{in instantiation of function template specialization 'foo5<int, float>' requested here}}
Clement Courbetfb2c74d2018-12-20 09:05:15 +000057
58struct ExampleTypes {
59 explicit ExampleTypes(int);
60 using T = int;
61 using U = float;
62};
63
64template <class T>
65struct X {
66 int i = 0;
67 int j = 0;
68 constexpr operator bool() const { return false; }
69};
70
71template <class T>
72void foo6() {
73 static_assert(X<typename T::T>());
74 // expected-error@-1{{static_assert failed due to requirement 'X<int>()'}}
75 static_assert(X<typename T::T>{});
76 // expected-error@-1{{static_assert failed due to requirement 'X<int>{}'}}
77 static_assert(X<typename T::T>{1, 2});
78 // expected-error@-1{{static_assert failed due to requirement 'X<int>{1, 2}'}}
79 static_assert(X<typename T::T>({1, 2}));
80 // expected-error@-1{{static_assert failed due to requirement 'X<int>({1, 2})'}}
81 static_assert(typename T::T{0});
82 // expected-error@-1{{static_assert failed due to requirement 'int{0}'}}
83 static_assert(typename T::T(0));
84 // expected-error@-1{{static_assert failed due to requirement 'int(0)'}}
85 static_assert(sizeof(X<typename T::T>) == 0);
86 // expected-error@-1{{static_assert failed due to requirement 'sizeof(X<int>) == 0'}}
87 static_assert((const X<typename T::T> *)nullptr);
88 // expected-error@-1{{static_assert failed due to requirement '(const X<int> *)nullptr'}}
89 static_assert(static_cast<const X<typename T::T> *>(nullptr));
90 // expected-error@-1{{static_assert failed due to requirement 'static_cast<const X<int> *>(nullptr)'}}
91 static_assert((const X<typename T::T>[]){} == nullptr);
92 // expected-error@-1{{static_assert failed due to requirement '(X<int> const[0]){} == nullptr'}}
93 static_assert(sizeof(X<decltype(X<typename T::T>().X<typename T::T>::~X())>) == 0);
94 // expected-error@-1{{static_assert failed due to requirement 'sizeof(X<void>) == 0'}}
95}
96template void foo6<ExampleTypes>();
97// expected-note@-1{{in instantiation of function template specialization 'foo6<ExampleTypes>' requested here}}