xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/vtable-instantiation.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc namespace PR8640 {
4*0a6a1f1dSLionel Sambuc   template<class T1> struct C1 {
c1PR8640::C15*0a6a1f1dSLionel Sambuc     virtual void c1() {
6*0a6a1f1dSLionel Sambuc       T1 t1 = 3;  // expected-error {{cannot initialize a variable}}
7*0a6a1f1dSLionel Sambuc     }
8*0a6a1f1dSLionel Sambuc   };
9*0a6a1f1dSLionel Sambuc 
10*0a6a1f1dSLionel Sambuc   template<class T2> struct C2 {
c2PR8640::C211*0a6a1f1dSLionel Sambuc     void c2() {
12*0a6a1f1dSLionel Sambuc       new C1<T2>();  // expected-note {{in instantiation of member function}}
13*0a6a1f1dSLionel Sambuc     }
14*0a6a1f1dSLionel Sambuc   };
15*0a6a1f1dSLionel Sambuc 
f()16*0a6a1f1dSLionel Sambuc   void f() {
17*0a6a1f1dSLionel Sambuc     C2<int*> c2;
18*0a6a1f1dSLionel Sambuc     c2.c2();  // expected-note {{in instantiation of member function}}
19*0a6a1f1dSLionel Sambuc   }
20*0a6a1f1dSLionel Sambuc }
21*0a6a1f1dSLionel Sambuc 
22*0a6a1f1dSLionel Sambuc namespace PR9325 {
23*0a6a1f1dSLionel Sambuc   template<typename T>
24*0a6a1f1dSLionel Sambuc   class Target
25*0a6a1f1dSLionel Sambuc   {
26*0a6a1f1dSLionel Sambuc   public:
Value() const27*0a6a1f1dSLionel Sambuc     virtual T Value() const
28*0a6a1f1dSLionel Sambuc     {
29*0a6a1f1dSLionel Sambuc       return 1; // expected-error{{cannot initialize return object of type 'int *' with an rvalue of type 'int'}}
30*0a6a1f1dSLionel Sambuc     }
31*0a6a1f1dSLionel Sambuc   };
32*0a6a1f1dSLionel Sambuc 
33*0a6a1f1dSLionel Sambuc   template<typename T>
34*0a6a1f1dSLionel Sambuc   struct Provider
35*0a6a1f1dSLionel Sambuc   {
36*0a6a1f1dSLionel Sambuc     static Target<T> Instance;
37*0a6a1f1dSLionel Sambuc   };
38*0a6a1f1dSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc   template<typename T>
40*0a6a1f1dSLionel Sambuc   Target<T> Provider<T>::Instance; // expected-note{{in instantiation of}}
41*0a6a1f1dSLionel Sambuc 
f()42*0a6a1f1dSLionel Sambuc   void f()
43*0a6a1f1dSLionel Sambuc   {
44*0a6a1f1dSLionel Sambuc     Target<int*>* traits = &Provider<int*>::Instance; // expected-note{{requested here}}
45*0a6a1f1dSLionel Sambuc   }
46*0a6a1f1dSLionel Sambuc }
47*0a6a1f1dSLionel Sambuc 
48*0a6a1f1dSLionel Sambuc namespace PR10020 {
49*0a6a1f1dSLionel Sambuc   struct MG {
50*0a6a1f1dSLionel Sambuc     virtual void Accept(int) = 0;
51*0a6a1f1dSLionel Sambuc   };
52*0a6a1f1dSLionel Sambuc 
53*0a6a1f1dSLionel Sambuc   template <typename Type>
54*0a6a1f1dSLionel Sambuc   struct GMG : MG {
AcceptPR10020::GMG55*0a6a1f1dSLionel Sambuc     void Accept(int i) {
56*0a6a1f1dSLionel Sambuc       static_cast<Type *>(0)->Accept(i); // expected-error{{member reference base}}
57*0a6a1f1dSLionel Sambuc     }
MethodPR10020::GMG58*0a6a1f1dSLionel Sambuc     static GMG* Method() { return &singleton; } // expected-note{{in instantiation of}}
59*0a6a1f1dSLionel Sambuc     static GMG singleton;
60*0a6a1f1dSLionel Sambuc   };
61*0a6a1f1dSLionel Sambuc 
62*0a6a1f1dSLionel Sambuc   template <typename Type>
63*0a6a1f1dSLionel Sambuc   GMG<Type> GMG<Type>::singleton; // expected-note{{requested here}}
64*0a6a1f1dSLionel Sambuc 
test(void)65*0a6a1f1dSLionel Sambuc   void test(void) {
66*0a6a1f1dSLionel Sambuc     GMG<int>::Method(); // expected-note{{in instantiation of}}
67*0a6a1f1dSLionel Sambuc   }
68*0a6a1f1dSLionel Sambuc }
69