1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
5 // RUN: not %clang_cc1 -x c++ -fixit %t -DFIXING
6 // RUN: %clang_cc1 -x c++ %t -DFIXING
8 template<typename T> void f(T) { }
9 #if __cplusplus >= 201103L
10 // expected-note@-2 {{explicit instantiation refers here}}
13 template<typename T> void g(T) { }
14 #if __cplusplus >= 201103L
15 // expected-note@-2 {{explicit instantiation refers here}}
18 template<typename T> struct x { };
19 #if __cplusplus >= 201103L
20 // expected-note@-2 {{explicit instantiation refers here}}
23 template<typename T> struct y { }; // expected-note {{declared here}}
25 namespace good { // Only good in C++98/03
27 template void f<int>(int);
28 #if __cplusplus >= 201103L
29 // expected-error@-2 {{explicit instantiation of 'f' must occur at global scope}}
33 #if __cplusplus >= 201103L
34 // expected-error@-2 {{explicit instantiation of 'g' must occur at global scope}}
37 template struct x<int>;
38 #if __cplusplus >= 201103L
39 // expected-error@-2 {{explicit instantiation of 'x' must occur at global scope}}
44 namespace unsupported {
46 template struct y; // expected-error {{template 'y' cannot be referenced with a struct specifier}}
50 template<typename T> void f0(T) { }
51 template<typename T> void g0(T) { }
52 template<typename T> struct x0 { }; // expected-note {{explicitly specialized declaration is here}}
53 template<typename T> struct y0 { };
55 // Should recover as if definition
56 namespace noargs_body {
58 template void g0(int) { } // expected-error {{function cannot be defined in an explicit instantiation; if this declaration is meant to be a function definition, remove the 'template' keyword}}
60 template struct y0 { }; // expected-error {{class cannot be defined in an explicit instantiation; if this declaration is meant to be a class definition, remove the 'template' keyword}}
63 // Explicit specializations expected in global scope
66 template<> void f0<int>(int) { } // expected-error {{no function template matches function template specialization 'f0'}}
67 template<> struct x0<int> { }; // expected-error {{class template specialization of 'x0' must occur at global scope}}
71 template<typename T> void f1(T) { }
72 template<typename T> struct x1 { }; // expected-note {{explicitly specialized declaration is here}}
74 // Should recover as if specializations,
75 // thus also complain about not being in global scope.
78 template void f1<int>(int) { } // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}} \
79 expected-error {{no function template matches function template specialization 'f1'}}
80 template struct x1<int> { }; // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}} \
81 expected-error {{class template specialization of 'x1' must occur at global scope}}
85 template<typename T> void f2(T) { }
86 template<typename T> struct x2 { };
88 // Should recover as if specializations
89 template void f2<int>(int) { } // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}}
90 template struct x2<int> { }; // expected-error {{explicit template instantiation cannot have a definition; if this definition is meant to be an explicit specialization, add '<>' after the 'template' keyword}}