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
diff --git a/test/SemaTemplate/class-template-spec.cpp b/test/SemaTemplate/class-template-spec.cpp
index 4de220a..4ae1b9b 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 @@
 
 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 @@
 }
 
 // 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}}
+}