diff options
author | Larisse Voufo <lvoufo@google.com> | 2013-06-21 00:08:46 +0000 |
---|---|---|
committer | Larisse Voufo <lvoufo@google.com> | 2013-06-21 00:08:46 +0000 |
commit | 725de3e14ff288a92bed36241cdc2c22be55ee0e (patch) | |
tree | 75a18311dbe16010eaf81c924f5d03f4f292fe09 /clang/test | |
parent | 2c75f11e86ee8bff73a935b7542712f5255f4535 (diff) | |
download | bcm5719-llvm-725de3e14ff288a92bed36241cdc2c22be55ee0e.tar.gz bcm5719-llvm-725de3e14ff288a92bed36241cdc2c22be55ee0e.zip |
Bug Fix: Template explicit instantiations should not have definitions (FixIts yet to be tested.)
llvm-svn: 184503
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/temp/temp.spec/no-body.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/clang/test/CXX/temp/temp.spec/no-body.cpp b/clang/test/CXX/temp/temp.spec/no-body.cpp new file mode 100644 index 00000000000..c2434a8c948 --- /dev/null +++ b/clang/test/CXX/temp/temp.spec/no-body.cpp @@ -0,0 +1,52 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template<typename T> void f(T) { } +template<typename T> void g(T) { } +template<typename T> struct x { }; +template<typename T> struct y { }; // expected-note {{declared here}} + +namespace good { + template void f<int>(int); + template void g(int); + template struct x<int>; +} + +namespace unsupported { + template struct y; // expected-error {{elaborated type refers to a template}} +} + +template<typename T> void f0(T) { } +template<typename T> void g0(T) { } +template<typename T> struct x0 { }; // expected-note {{explicitly specialized declaration is here}} +template<typename T> struct y0 { }; + +// Should recover as if definition +namespace noargs_body { + 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}} + 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}} +} + +// Explicit specializations expected in global scope +namespace exp_spec { + template<> void f0<int>(int) { } // expected-error {{no function template matches function template specialization 'f0'}} + template<> struct x0<int> { }; // expected-error {{class template specialization of 'x0' must originally be declared in the global scope}} +} + +template<typename T> void f1(T) { } +template<typename T> struct x1 { }; // expected-note {{explicitly specialized declaration is here}} + +// Should recover as if specializations, +// thus also complain about not being in global scope. +namespace args_bad { + 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}} \ + expected-error {{no function template matches function template specialization 'f1'}} + 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}} \ + expected-error {{class template specialization of 'x1' must originally be declared in the global scope}} +} + +template<typename T> void f2(T) { } +template<typename T> struct x2 { }; + +// Should recover as if specializations +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}} +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}} |