| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-c++20-extensions |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions -std=c++98 %s |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
| 4 |
|
| 5 |
namespace N { |
| 6 |
namespace M { |
| 7 |
template<typename T> struct Promote; |
| 8 |
|
| 9 |
template<> struct Promote<short> { |
| 10 |
typedef int type; |
| 11 |
}; |
| 12 |
|
| 13 |
template<> struct Promote<int> { |
| 14 |
typedef int type; |
| 15 |
}; |
| 16 |
|
| 17 |
template<> struct Promote<float> { |
| 18 |
typedef double type; |
| 19 |
}; |
| 20 |
|
| 21 |
Promote<short>::type *ret_intptr(int* ip) { return ip; } |
| 22 |
Promote<int>::type *ret_intptr2(int* ip) { return ip; } |
| 23 |
} |
| 24 |
|
| 25 |
M::Promote<int>::type *ret_intptr3(int* ip) { return ip; } |
| 26 |
M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } |
| 27 |
M::template Promote<int> pi; |
| 28 |
} |
| 29 |
|
| 30 |
N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; } |
| 31 |
::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; } |
| 32 |
|
| 33 |
|
| 34 |
N::M::template; // expected-error{{expected unqualified-id}} |
| 35 |
N::M::template Promote; // expected-error{{expected unqualified-id}} |
| 36 |
|
| 37 |
namespace N { |
| 38 |
template<typename T> struct A; |
| 39 |
|
| 40 |
template<> |
| 41 |
struct A<int> { |
| 42 |
struct X; |
| 43 |
}; |
| 44 |
|
| 45 |
struct B; // expected-note{{declared as a non-template here}} |
| 46 |
} |
| 47 |
|
| 48 |
struct ::N::A<int>::X { |
| 49 |
int foo; |
| 50 |
}; |
| 51 |
|
| 52 |
template<typename T> |
| 53 |
struct TestA { |
| 54 |
typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}} |
| 55 |
}; |
| 56 |
|
| 57 |
// Reduced from a Boost failure. |
| 58 |
namespace test1 { |
| 59 |
template <class T> struct pair { |
| 60 |
T x; |
| 61 |
T y; |
| 62 |
|
| 63 |
static T pair<T>::* const mem_array[2]; |
| 64 |
}; |
| 65 |
|
| 66 |
template <class T> |
| 67 |
T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y }; |
| 68 |
} |
| 69 |
|
| 70 |
typedef int T; |
| 71 |
namespace N1 { |
| 72 |
template<typename T> T f0(); |
| 73 |
} |
| 74 |
|
| 75 |
template<typename T> T N1::f0() { } |
| 76 |
|
| 77 |
namespace PR7385 { |
| 78 |
template< typename > struct has_xxx0 |
| 79 |
{ |
| 80 |
template< typename > struct has_xxx0_introspect |
| 81 |
{ |
| 82 |
template< typename > struct has_xxx0_substitute ; |
| 83 |
template< typename V > |
| 84 |
int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 ); |
| 85 |
}; |
| 86 |
static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}} |
| 87 |
typedef int type; |
| 88 |
}; |
| 89 |
|
| 90 |
has_xxx0<int>::type t; // expected-note{{instantiation of}} |
| 91 |
} |
| 92 |
|
| 93 |
namespace PR7725 { |
| 94 |
template<class ignored> struct TypedefProvider; |
| 95 |
template<typename T> |
| 96 |
struct TemplateClass : public TypedefProvider<T> |
| 97 |
{ |
| 98 |
void PrintSelf() { |
| 99 |
TemplateClass::Test::PrintSelf(); |
| 100 |
} |
| 101 |
}; |
| 102 |
} |
| 103 |
|
| 104 |
namespace PR9226 { |
| 105 |
template<typename a> |
| 106 |
void nt() // expected-note{{function template 'nt' declared here}} |
| 107 |
{ nt<>:: } // expected-error{{qualified name refers into a specialization of function template 'nt'}} \ |
| 108 |
// expected-error{{expected unqualified-id}} |
| 109 |
|
| 110 |
template<typename T> |
| 111 |
void f(T*); // expected-note{{function template 'f' declared here}} |
| 112 |
|
| 113 |
template<typename T> |
| 114 |
void f(T*, T*); // expected-note{{function template 'f' declared here}} |
| 115 |
|
| 116 |
void g() { |
| 117 |
f<int>:: // expected-error{{qualified name refers into a specialization of function template 'f'}} |
| 118 |
} // expected-error{{expected unqualified-id}} |
| 119 |
|
| 120 |
struct X { |
| 121 |
template<typename T> void f(); // expected-note{{function template 'f' declared here}} |
| 122 |
}; |
| 123 |
|
| 124 |
template<typename T, typename U> |
| 125 |
struct Y { |
| 126 |
typedef typename T::template f<U> type; // expected-error{{template name refers to non-type template 'PR9226::X::template f'}} |
| 127 |
}; |
| 128 |
|
| 129 |
Y<X, int> yxi; // expected-note{{in instantiation of template class 'PR9226::Y<PR9226::X, int>' requested here}} |
| 130 |
} |
| 131 |
|
| 132 |
namespace PR9449 { |
| 133 |
template <typename T> |
| 134 |
struct s; // expected-note{{template is declared here}} |
| 135 |
|
| 136 |
template <typename T> |
| 137 |
void f() { |
| 138 |
int s<T>::template n<T>::* f; // expected-error{{implicit instantiation of undefined template 'PR9449::s<int>'}} |
| 139 |
} |
| 140 |
|
| 141 |
template void f<int>(); // expected-note{{in instantiation of}} |
| 142 |
} |
| 143 |
|
| 144 |
namespace sugared_template_instantiation { |
| 145 |
// Test that we ignore local qualifiers. |
| 146 |
template <class A1, class = typename A1::type1> struct A {}; |
| 147 |
struct B { typedef int type1; }; |
| 148 |
typedef A<const B> type2; |
| 149 |
} // namespace sugated_template_instantiation |
| 150 |
|
| 151 |
namespace unresolved_using { |
| 152 |
template <class> struct A { |
| 153 |
struct B { |
| 154 |
typedef int X; |
| 155 |
}; |
| 156 |
}; |
| 157 |
template <class T> struct C : A<T> { |
| 158 |
using typename A<T>::B; |
| 159 |
typedef typename B::X Y; |
| 160 |
}; |
| 161 |
template struct C<int>; |
| 162 |
} // namespace unresolved_using |
| 163 |
|
| 164 |
#if __cplusplus >= 201703L |
| 165 |
namespace SubstTemplateTypeParmPackType { |
| 166 |
template <int...> struct A {}; |
| 167 |
|
| 168 |
template <class... Ts> void f() { |
| 169 |
[]<int ... Is>(A<Is...>) { (Ts::g(Is) && ...); }(A<0>{}); |
| 170 |
}; |
| 171 |
|
| 172 |
struct B { static void g(int); }; |
| 173 |
|
| 174 |
template void f<B>(); |
| 175 |
} // namespace SubstTemplateTypeParmPackType |
| 176 |
#endif |
| 177 |
|
| 178 |
namespace DependentUnaryTransform { |
| 179 |
template <class T> using decay_t = __decay(T); |
| 180 |
template <class, class> struct A; |
| 181 |
template <class T> struct A<T, typename decay_t<T>::X>; |
| 182 |
} // namespace DependentUnaryTransform |
| 183 |
|
| 184 |
namespace DependentSizedArray { |
| 185 |
template <int V> using Z = int[V]; |
| 186 |
template <class, class> struct A; |
| 187 |
template <class T> struct A<T, typename Z<T(0)>::X>; |
| 188 |
} // namespace DependentUnaryTransform |
| 189 |
|
| 190 |
namespace GH155281 { |
| 191 |
template <bool> struct enable_if; |
| 192 |
template <class _Tp, _Tp> struct integral_constant; |
| 193 |
template <typename> struct conjunction; |
| 194 |
template <typename T> using value_type_t = T; |
| 195 |
template <class Check> using require_t = typename enable_if<Check::value>::type; |
| 196 |
template <template <class> class, template <class> class, |
| 197 |
template <class> class, class... Check> |
| 198 |
using container_type_check_base = |
| 199 |
integral_constant<bool, conjunction<Check...>::value>; |
| 200 |
template <typename> struct is_std_vector; |
| 201 |
template <template <class> class TypeCheck, class... Check> |
| 202 |
using require_std_vector_vt = |
| 203 |
require_t<container_type_check_base<is_std_vector, value_type_t, TypeCheck, |
| 204 |
Check...> >; |
| 205 |
template <typename, typename> class vector_seq_view; |
| 206 |
namespace internal { |
| 207 |
template <typename> using is_matrix_or_std_vector = int; |
| 208 |
} |
| 209 |
template <typename T> |
| 210 |
class vector_seq_view< |
| 211 |
T, require_std_vector_vt<internal::is_matrix_or_std_vector, T> >; |
| 212 |
} // namespace GH155281 |