xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/explicit-specialization-member.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc template<typename T>
3f4a2713aSLionel Sambuc struct X0 {
4f4a2713aSLionel Sambuc   typedef T* type;
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc   void f0(T);
7f4a2713aSLionel Sambuc   void f1(type);
8f4a2713aSLionel Sambuc };
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc template<> void X0<char>::f0(char);
11f4a2713aSLionel Sambuc template<> void X0<char>::f1(type);
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc namespace PR6161 {
14f4a2713aSLionel Sambuc   template<typename _CharT>
15f4a2713aSLionel Sambuc   class numpunct : public locale::facet // expected-error{{use of undeclared identifier 'locale'}} \
16f4a2713aSLionel Sambuc               // expected-error{{expected class name}}
17f4a2713aSLionel Sambuc   {
18f4a2713aSLionel Sambuc     static locale::id id; // expected-error{{use of undeclared identifier}}
19f4a2713aSLionel Sambuc   };
20f4a2713aSLionel Sambuc   numpunct<char>::~numpunct(); // expected-error{{expected the class name after '~' to name a destructor}}
21f4a2713aSLionel Sambuc }
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc namespace PR12331 {
24f4a2713aSLionel Sambuc   template<typename T> struct S {
25f4a2713aSLionel Sambuc     struct U { static const int n = 5; };
26f4a2713aSLionel Sambuc     enum E { e = U::n }; // expected-note {{implicit instantiation first required here}}
27f4a2713aSLionel Sambuc     int arr[e];
28f4a2713aSLionel Sambuc   };
29f4a2713aSLionel Sambuc   template<> struct S<int>::U { static const int n = sizeof(int); }; // expected-error {{explicit specialization of 'U' after instantiation}}
30f4a2713aSLionel Sambuc }
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc namespace PR18246 {
33*0a6a1f1dSLionel Sambuc   template<typename T>
34*0a6a1f1dSLionel Sambuc   class Baz {
35*0a6a1f1dSLionel Sambuc   public:
36*0a6a1f1dSLionel Sambuc     template<int N> void bar();
37*0a6a1f1dSLionel Sambuc   };
38*0a6a1f1dSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc   template<typename T>
40*0a6a1f1dSLionel Sambuc   template<int N>
bar()41*0a6a1f1dSLionel Sambuc   void Baz<T>::bar() { // expected-note {{couldn't infer template argument 'N'}}
42*0a6a1f1dSLionel Sambuc   }
43*0a6a1f1dSLionel Sambuc 
44*0a6a1f1dSLionel Sambuc   // FIXME: We shouldn't try to match this against a prior declaration if
45*0a6a1f1dSLionel Sambuc   // template parameter matching failed.
46*0a6a1f1dSLionel Sambuc   template<typename T>
bar()47*0a6a1f1dSLionel Sambuc   void Baz<T>::bar<0>() { // expected-error {{cannot specialize a member of an unspecialized template}} \
48*0a6a1f1dSLionel Sambuc                           // expected-error {{no function template matches}}
49*0a6a1f1dSLionel Sambuc   }
50*0a6a1f1dSLionel Sambuc }
51*0a6a1f1dSLionel Sambuc 
52*0a6a1f1dSLionel Sambuc namespace PR19340 {
53*0a6a1f1dSLionel Sambuc template<typename T> struct Helper {
funcPR19340::Helper54*0a6a1f1dSLionel Sambuc   template<int N> static void func(const T *m) {} // expected-note {{failed template argument deduction}}
55*0a6a1f1dSLionel Sambuc };
56*0a6a1f1dSLionel Sambuc 
func()57*0a6a1f1dSLionel Sambuc template<typename T> void Helper<T>::func<2>() {} // expected-error {{cannot specialize a member}} \
58*0a6a1f1dSLionel Sambuc                                                   // expected-error {{no function template matches}}
59*0a6a1f1dSLionel Sambuc }
60