no-body.cpp revision 472e66e9d32e587a028bc676aa63bd7137f3d4d4
1// RUN: %clang_cc1 -fsyntax-only -verify %s 2// RUN: cp %s %t 3// RUN: not %clang_cc1 -fsyntax-only -fixit -x c++ %t 4// RUN: grep test_string %t 5 6template<typename T> void f(T) { } 7template<typename T> void g(T) { } 8template<typename T> struct x { }; 9template<typename T> struct y { }; // expected-note {{declared here}} 10 11namespace good { 12 template void f<int>(int); 13 template void g(int); 14 template struct x<int>; 15} 16 17namespace unsupported { 18 template struct y; // expected-error {{elaborated type refers to a template}} 19} 20 21template<typename T> void f0(T) { } 22template<typename T> void g0(T) { } 23template<typename T> struct x0 { }; // expected-note {{explicitly specialized declaration is here}} 24template<typename T> struct y0 { }; 25 26// Should recover as if definition 27namespace noargs_body { 28 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}} 29 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}} 30} 31 32// Explicit specializations expected in global scope 33namespace exp_spec { 34 template<> void f0<int>(int) { } // expected-error {{no function template matches function template specialization 'f0'}} 35 template<> struct x0<int> { }; // expected-error {{class template specialization of 'x0' must originally be declared in the global scope}} 36} 37 38template<typename T> void f1(T) { } 39template<typename T> struct x1 { }; // expected-note {{explicitly specialized declaration is here}} 40 41// Should recover as if specializations, 42// thus also complain about not being in global scope. 43namespace args_bad { 44 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}} \ 45 expected-error {{no function template matches function template specialization 'f1'}} 46 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}} \ 47 expected-error {{class template specialization of 'x1' must originally be declared in the global scope}} 48} 49 50template<typename T> void f2(T) { } 51template<typename T> struct x2 { }; 52 53// Should recover as if specializations 54template 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}} 55template 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}} 56