blob: 2a1b98900647443b134b6130f4315bb8f002b917 [file] [log] [blame]
Nick Lewycky2a5f99e2010-11-25 00:35:20 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Nick Lewycky2a5f99e2010-11-25 00:35:20 +00002
Nick Lewycky81559102011-05-31 07:58:42 +00003namespace PR8640 {
4 template<class T1> struct C1 {
5 virtual void c1() {
6 T1 t1 = 3; // expected-error {{cannot initialize a variable}}
7 }
8 };
9
10 template<class T2> struct C2 {
11 void c2() {
12 new C1<T2>(); // expected-note {{in instantiation of member function}}
13 }
14 };
15
16 void f() {
17 C2<int*> c2;
18 c2.c2(); // expected-note {{in instantiation of member function}}
Nick Lewycky2a5f99e2010-11-25 00:35:20 +000019 }
Nick Lewycky2a5f99e2010-11-25 00:35:20 +000020}
21
Douglas Gregor78844032011-04-22 22:25:37 +000022namespace PR9325 {
23 template<typename T>
24 class Target
25 {
26 public:
27 virtual T Value() const
28 {
29 return 1; // expected-error{{cannot initialize return object of type 'int *' with an rvalue of type 'int'}}
30 }
31 };
32
33 template<typename T>
34 struct Provider
35 {
36 static Target<T> Instance;
37 };
38
39 template<typename T>
40 Target<T> Provider<T>::Instance; // expected-note{{in instantiation of}}
41
42 void f()
43 {
44 Target<int*>* traits = &Provider<int*>::Instance;
45 }
Nick Lewycky81559102011-05-31 07:58:42 +000046}
Douglas Gregor78844032011-04-22 22:25:37 +000047
Nick Lewycky81559102011-05-31 07:58:42 +000048namespace PR10020 {
49 struct MG {
50 virtual void Accept(int) = 0;
51 };
52
53 template <typename Type>
54 struct GMG : MG {
55 void Accept(int i) {
56 static_cast<Type *>(0)->Accept(i); // expected-error{{member reference base}}
57 }
58 static GMG* Method() { return &singleton; } // expected-note{{in instantiation of}}
59 static GMG singleton;
60 };
61
62 template <typename Type>
63 GMG<Type> GMG<Type>::singleton;
64
65 void test(void) {
66 GMG<int>::Method(); // expected-note{{in instantiation of}}
67 }
Douglas Gregor78844032011-04-22 22:25:37 +000068}