blob: 422364c155ba25fb12435468b394d05b113376e9 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor2dc0e642009-03-23 23:06:20 +00002template<typename T>
3class X {
4public:
Douglas Gregor5545e162009-03-24 00:38:23 +00005 void f(T x); // expected-error{{argument may not have 'void' type}}
Douglas Gregor2dc0e642009-03-23 23:06:20 +00006 void g(T*);
7
8 static int h(T, T); // expected-error 2{{argument may not have 'void' type}}
9};
10
11int identity(int x) { return x; }
12
13void test(X<int> *xi, int *ip, X<int(int)> *xf) {
14 xi->f(17);
15 xi->g(ip);
16 xf->f(&identity);
17 xf->g(identity);
18 X<int>::h(17, 25);
19 X<int(int)>::h(identity, &identity);
20}
21
22void test_bad() {
23 X<void> xv; // expected-note{{in instantiation of template class 'class X<void>' requested here}}
24}
25
26template<typename T, typename U>
27class Overloading {
28public:
29 int& f(T, T); // expected-note{{previous declaration is here}}
30 float& f(T, U); // expected-error{{functions that differ only in their return type cannot be overloaded}}
31};
32
33void test_ovl(Overloading<int, long> *oil, int i, long l) {
34 int &ir = oil->f(i, i);
35 float &fr = oil->f(i, l);
36}
37
38void test_ovl_bad() {
39 Overloading<float, float> off; // expected-note{{in instantiation of template class 'class Overloading<float, float>' requested here}}
40}
Douglas Gregor03b2b072009-03-24 00:15:49 +000041
42template<typename T>
43class HasDestructor {
Douglas Gregor615c5d42009-03-24 16:43:20 +000044public:
Douglas Gregor03b2b072009-03-24 00:15:49 +000045 virtual ~HasDestructor() = 0;
46};
47
48int i = sizeof(HasDestructor<int>); // FIXME: forces instantiation, but
49 // the code below should probably instantiate by itself.
50int abstract_destructor[__is_abstract(HasDestructor<int>)? 1 : -1];
Douglas Gregor615c5d42009-03-24 16:43:20 +000051
52
53template<typename T>
54class Constructors {
55public:
56 Constructors(const T&);
57 Constructors(const Constructors &other);
58};
59
60void test_constructors() {
61 Constructors<int> ci1(17);
62 Constructors<int> ci2 = ci1;
63}
Douglas Gregorbb969ed2009-03-25 00:34:44 +000064
65
66template<typename T>
67struct ConvertsTo {
68 operator T();
69};
70
71void test_converts_to(ConvertsTo<int> ci, ConvertsTo<int *> cip) {
72 int i = ci;
73 int *ip = cip;
74}
Douglas Gregor5842ba92009-08-24 15:23:48 +000075
76// PR4660
77template<class T> struct A0 { operator T*(); };
78template<class T> struct A1;
79
80int *a(A0<int> &x0, A1<int> &x1) {
81 int *y0 = x0;
82 int *y1 = x1; // expected-error{{initializing}}
83}
Douglas Gregor7a343142009-11-01 17:08:18 +000084
85struct X0Base {
86 int &f();
Douglas Gregorf3c1f0e2009-11-20 00:59:20 +000087 int& g(int);
88 static double &g(double);
Douglas Gregor7a343142009-11-01 17:08:18 +000089};
90
91template<typename T>
92struct X0 : X0Base {
93};
94
95template<typename U>
96struct X1 : X0<U> {
Douglas Gregorf3c1f0e2009-11-20 00:59:20 +000097 int &f2() {
John McCallaa81e162009-12-01 22:10:20 +000098 return X0Base::f();
Douglas Gregorf3c1f0e2009-11-20 00:59:20 +000099 }
Douglas Gregor7a343142009-11-01 17:08:18 +0000100};
101
102void test_X1(X1<int> x1i) {
103 int &ir = x1i.f2();
104}
Douglas Gregorf3c1f0e2009-11-20 00:59:20 +0000105
106template<typename U>
107struct X2 : X0Base, U {
108 int &f2() { return X0Base::f(); }
109};
110
111template<typename T>
112struct X3 {
113 void test(T x) {
114 double& d1 = X0Base::g(x);
115 }
116};
117
118
119template struct X3<double>;