1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++03 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
5 template<typename FromCl
>
8 static void isa(const FromCl
&Val
) { }
11 template<class X
, class Y
>
12 void isa(const Y
&Val
) { return isa_impl_cl
<Y
>::template isa
<X
>(Val
); }
15 void f0(const Value
&Val
) { isa
<Value
>(Val
); }
17 // Implicit template-ids.
29 void test_X0_int(X0
<int> xi
, float f
) {
33 // Not template-id expressions, but they almost look like it.
44 Y
<X
<I
> >(::X
<I
>(0, 0));
50 // 'template' as a disambiguator.
59 void f3(int); // expected-note 2{{declared as a non-template here}}
67 Y0::template f1
<U
>(0);
68 Y0::template f1(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
69 this->template f1(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
71 Y0::template f2
<U
>(0);
72 Y0::template f2(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
74 Y0::template f3(0); // expected-error {{'f3' following the 'template' keyword does not refer to a template}}
75 Y0::template f3(); // expected-error {{'f3' following the 'template' keyword does not refer to a template}}
79 x
= Y0::f4
<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}}
80 x
= Y0::template f4(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}} expected-error {{assigning to 'int' from incompatible type 'void'}}
83 x
= this->f4
<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}}
84 x
= this->template f4(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}} expected-error {{assigning to 'int' from incompatible type 'void'}}
88 template<typename U
> void Y0
89 ::template // expected-error {{expected unqualified-id}}
92 // FIXME: error recovery is awful without this.
103 void f3(int); // expected-note 4{{declared as a non-template here}}
111 Y1::template f1
<U
>(0);
112 Y1::template f1(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
113 this->template f1(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
115 Y1::template f2
<U
>(0);
116 Y1::template f2(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
118 Y1::template f3(0); // expected-error {{'f3' following the 'template' keyword does not refer to a template}}
119 Y1::template f3(); // expected-error {{'f3' following the 'template' keyword does not refer to a template}}
123 x
= Y1::f4
<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}}
124 x
= Y1::template f4(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}} expected-error {{assigning to 'int' from incompatible type 'void'}}
127 x
= this->f4
<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}}
128 x
= this->template f4(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}} expected-error {{assigning to 'int' from incompatible type 'void'}}
132 void use_Y1(Y1
<int> y1
) { y1
.f
<int>(); } // expected-note {{in instantiation of}}
140 Y1::template f1
<U
>(0);
141 Y1::template f1(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
142 p
->template f1(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
144 Y1::template f2
<U
>(0);
145 Y1::template f2(0); // expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
147 Y1::template f3(0); // expected-error {{'f3' following the 'template' keyword does not refer to a template}} expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
148 Y1::template f3(); // expected-error {{'f3' following the 'template' keyword does not refer to a template}} expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
152 x
= Y1::f4
<int>(0); // expected-error {{use 'template'}} expected-error {{assigning to 'int' from incompatible type 'void'}}
153 x
= Y1::template f4(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
156 x
= p
->f4
<int>(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} expected-error {{use 'template'}}
157 x
= p
->template f4(0); // expected-error {{assigning to 'int' from incompatible type 'void'}} expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
161 void use_Y2(Y2
<int> y2
) { y2
.f
<int>(0); } // expected-note {{in instantiation of}}
166 static void b1(); // expected-note {{declared as a non-template here}}
172 A::template B
<I
>::template b1(); // expected-error {{'b1' following the 'template' keyword does not refer to a template}} expected-error {{a template argument list is expected after a name prefixed by the template keyword}}
175 template void f5
<0>(); // expected-note {{in instantiation of function template specialization 'f5<0>' requested here}}
178 template <template <typename
> class D
>
180 template class D
<C
>; // expected-error {{expected '<' after 'template'}}
181 template<> class D
<C
>; // expected-error {{cannot specialize a template template parameter}}
182 friend class D
<C
>; // expected-error {{alias template 'D' cannot be referenced with the 'class' specifier}}
184 #if __cplusplus <= 199711L
185 // expected-warning@+2 {{extension}}
187 template<typename T
> using D
= int; // expected-note {{declared here}}
188 E
<D
> ed
; // expected-note {{instantiation of}}
190 namespace non_functions
{
192 #if __cplusplus >= 201103L
194 template <typename T
> struct O
{
195 static const T v
= 0;
199 template <typename T
> using I
= typename O
<T
>::v
; // #TypeAlias
203 template <typename T
> int foo() {
204 return T::template I
<int>;
205 // expected-error@-1 {{'P::I' is expected to be a non-type template, but instantiated to a type alias template}}
206 // expected-note@#TypeAlias {{type alias template declared here}}
211 return Q().foo
<P
>(); // expected-note-re {{function template specialization {{.*}} requested here}}
214 } // namespace PR88832
220 template <class T
> struct add_pointer
{ // #add_pointer
227 std::__add_pointer
<A
>::type ptr
;
228 // expected-warning@-1 {{keyword '__add_pointer' will be made available as an identifier here}}
229 // expected-error@-2 {{no template named '__add_pointer'}}
230 // expected-note@#add_pointer {{'add_pointer' declared here}}
231 // expected-error-re@-4 {{no type named 'type' in '{{.*}}std::add_pointer<{{.*}}A>'}}
233 __add_pointer
<A
>::type ptr2
;
234 // expected-error@-1 {{no template named '__add_pointer'}}
235 // expected-error-re@-2 {{no type named 'type' in '{{.*}}std::add_pointer<{{.*}}A>'}}
236 // expected-note@#add_pointer {{'std::add_pointer' declared here}}
239 } // namespace PR63243
243 template <typename T
> struct C
{
244 template <int TT
> class Type
{}; // #ClassTemplate
247 template <typename T1
> struct A
{
249 template <typename T2
>
253 C
<T1
>::template Type
<2>;
254 // expected-error@-1 {{'C<float>::Type' is expected to be a non-type template, but instantiated to a class template}}}
255 // expected-note@#ClassTemplate {{class template declared here}}
257 foo(C
<T1
>::Type
<2>); // expected-error {{expected expression}}
259 foo(C
<T1
>::template Type
<2>);
260 // expected-error@-1 {{'C<float>::Type' is expected to be a non-type template, but instantiated to a class template}}
261 // expected-note@#ClassTemplate {{class template declared here}}
263 foo(C
<T1
>::template Type
<2>());
264 // expected-error@-1 {{'C<float>::Type' is expected to be a non-type template, but instantiated to a class template}}
265 // expected-error@-2 {{called object type '<dependent type>' is not a function or function pointer}}
266 // expected-note@#ClassTemplate {{class template declared here}}
268 foo(typename C
<T1
>::template Type
<2>());
273 A
<float>().foo(); // expected-note-re {{instantiation of member function {{.*}} requested here}}
276 } // namespace PR48673