diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-02-25 22:02:03 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-02-25 22:02:03 +0000 |
commit | 88b7094185b9d4fe9820c731b6936d8d37f6143e (patch) | |
tree | fcfbe4371945a1bf02a768521c3a30b73a5b5d2e /test/SemaTemplate/class-template-spec.cpp | |
parent | d76c6a38b8080b3255c37f787bcaf4a4724f330c (diff) |
Perform additional semantic checking of class template
specializations. In particular:
- Make sure class template specializations have a "template<>"
header, and complain if they don't.
- Make sure class template specializations are declared/defined
within a valid context. (e.g., you can't declare a specialization
std::vector<MyType> in the global namespace).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65476 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaTemplate/class-template-spec.cpp')
-rw-r--r-- | test/SemaTemplate/class-template-spec.cpp | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/test/SemaTemplate/class-template-spec.cpp b/test/SemaTemplate/class-template-spec.cpp index 4de220a77c..4ae1b9bdc9 100644 --- a/test/SemaTemplate/class-template-spec.cpp +++ b/test/SemaTemplate/class-template-spec.cpp @@ -1,13 +1,13 @@ // RUN: clang -fsyntax-only -verify %s -template<typename T, typename U = int> class A; +template<typename T, typename U = int> struct A; // expected-note{{template is declared here}} -template<> class A<double, double>; // expected-note{{forward declaration}} +template<> struct A<double, double>; // expected-note{{forward declaration}} -template<> class A<float, float> { // expected-note{{previous definition}} +template<> struct A<float, float> { // expected-note{{previous definition}} int x; }; -template<> class A<float> { // expected-note{{previous definition}} +template<> struct A<float> { // expected-note{{previous definition}} int y; }; @@ -24,16 +24,16 @@ int test_incomplete_specs(A<double, double> *a1, typedef float FLOAT; -template<> class A<float, FLOAT>; +template<> struct A<float, FLOAT>; -template<> class A<FLOAT, float> { }; // expected-error{{redefinition}} +template<> struct A<FLOAT, float> { }; // expected-error{{redefinition}} -template<> class A<float, int> { }; // expected-error{{redefinition}} +template<> struct A<float, int> { }; // expected-error{{redefinition}} -template<typename T, typename U = int> class X; +template<typename T, typename U = int> struct X; -template <> class X<int, int> { int foo(); }; // #1 -template <> class X<float> { int bar(); }; // #2 +template <> struct X<int, int> { int foo(); }; // #1 +template <> struct X<float> { int bar(); }; // #2 typedef int int_type; void testme(X<int_type> *x1, X<float, int> *x2) { @@ -42,4 +42,26 @@ void testme(X<int_type> *x1, X<float, int> *x2) { } // Diagnose specializations in a different namespace -class A<double> { }; +struct A<double> { }; // expected-error{{template specialization requires 'template<>'}} + +template<typename T> // expected-error{{class template partial specialization is not yet supported}} +struct A<T*> { }; + +template<> struct ::A<double>; + +namespace N { + template<typename T> struct B; // expected-note 2{{template is declared here}} + + template<> struct ::N::B<short>; // okay + template<> struct ::N::B<int>; // okay +} + +template<> struct N::B<int> { }; // okay + +template<> struct N::B<float> { }; // expected-error{{class template specialization of 'B' not in namespace 'N'}} + +namespace M { + template<> struct ::N::B<short> { }; // expected-error{{class template specialization of 'B' not in a namespace enclosing 'N'}} + + template<> struct ::A<long double>; // expected-error{{class template specialization of 'A' must occur in the global scope}} +} |