blob: a29e9d3a74969e9a903a8563e2810f242bdf9d46 [file] [log] [blame]
Hans Wennborgc9bd88e2014-01-14 19:35:09 +00001// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify %s
2// RUN: %clang_cc1 -triple %ms_abi_triple -DMSABI -fsyntax-only -verify %s
Douglas Gregorac1fb652009-03-24 19:52:54 +00003
4// Tests various places where requiring a complete type involves
5// instantiation of that type.
6
7template<typename T>
8struct X {
9 X(T);
10
Hans Wennborg9125b082014-01-13 19:48:13 +000011#ifdef MSABI
12// expected-error@+2{{data member instantiated with function type 'long (long)'}}
13#endif
Douglas Gregorac1fb652009-03-24 19:52:54 +000014 T f; // expected-error{{data member instantiated with function type 'float (int)'}} \
15 // expected-error{{data member instantiated with function type 'int (int)'}} \
16 // expected-error{{data member instantiated with function type 'char (char)'}} \
17 // expected-error{{data member instantiated with function type 'short (short)'}} \
Douglas Gregord07ba342010-10-13 20:41:14 +000018 // expected-error{{data member instantiated with function type 'float (float)'}}
Douglas Gregorac1fb652009-03-24 19:52:54 +000019};
20
21X<int> f() { return 0; }
22
23struct XField {
John McCall85f90552010-03-10 11:27:22 +000024 X<float(int)> xf; // expected-note{{in instantiation of template class 'X<float (int)>' requested here}}
Douglas Gregorac1fb652009-03-24 19:52:54 +000025};
26
27void test_subscript(X<double> *ptr1, X<int(int)> *ptr2, int i) {
28 (void)ptr1[i];
John McCall85f90552010-03-10 11:27:22 +000029 (void)ptr2[i]; // expected-note{{in instantiation of template class 'X<int (int)>' requested here}}
Douglas Gregorac1fb652009-03-24 19:52:54 +000030}
31
32void test_arith(X<signed char> *ptr1, X<unsigned char> *ptr2,
33 X<char(char)> *ptr3, X<short(short)> *ptr4) {
34 (void)(ptr1 + 5);
Douglas Gregorac1fb652009-03-24 19:52:54 +000035 (void)(5 + ptr2);
John McCall85f90552010-03-10 11:27:22 +000036 (void)(ptr3 + 5); // expected-note{{in instantiation of template class 'X<char (char)>' requested here}}
37 (void)(5 + ptr4); // expected-note{{in instantiation of template class 'X<short (short)>' requested here}}
Douglas Gregorac1fb652009-03-24 19:52:54 +000038}
39
40void test_new() {
41 (void)new X<float>(0);
John McCall85f90552010-03-10 11:27:22 +000042 (void)new X<float(float)>; // expected-note{{in instantiation of template class 'X<float (float)>' requested here}}
Douglas Gregorac1fb652009-03-24 19:52:54 +000043}
44
45void test_memptr(X<long> *p1, long X<long>::*pm1,
Douglas Gregor2ec748c2009-05-14 00:28:11 +000046 X<long(long)> *p2,
Hans Wennborg9125b082014-01-13 19:48:13 +000047#ifdef MSABI
48 long (X<long(long)>::*pm2)(long)) { // expected-note{{in instantiation of template class 'X<long (long)>' requested here}}
49#else
Douglas Gregor2ec748c2009-05-14 00:28:11 +000050 long (X<long(long)>::*pm2)(long)) {
Hans Wennborg9125b082014-01-13 19:48:13 +000051#endif
Douglas Gregorac1fb652009-03-24 19:52:54 +000052 (void)(p1->*pm1);
Douglas Gregorac1fb652009-03-24 19:52:54 +000053}
Douglas Gregor3ec1bf22009-11-05 13:06:35 +000054
55// Reference binding to a base
56template<typename T>
57struct X1 { };
58
59template<typename T>
60struct X2 : public T { };
61
62void refbind_base(X2<X1<int> > &x2) {
63 X1<int> &x1 = x2;
64}
65
66// Enumerate constructors for user-defined conversion.
67template<typename T>
68struct X3 {
69 X3(T);
70};
71
72void enum_constructors(X1<float> &x1) {
73 X3<X1<float> > x3 = x1;
74}
Douglas Gregora04f2ca2010-03-01 15:56:25 +000075
76namespace PR6376 {
77 template<typename T, typename U> struct W { };
78
79 template<typename T>
80 struct X {
81 template<typename U>
82 struct apply {
83 typedef W<T, U> type;
84 };
85 };
86
87 template<typename T, typename U>
88 struct Y : public X<T>::template apply<U>::type { };
89
90 template struct Y<int, float>;
91}
Douglas Gregord5c231e2010-04-24 21:09:25 +000092
93namespace TemporaryObjectCopy {
94 // Make sure we instantiate classes when we create a temporary copy.
95 template<typename T>
96 struct X {
97 X(T);
98 };
99
100 template<typename T>
101 void f(T t) {
102 const X<int> &x = X<int>(t);
103 }
104
105 template void f(int);
106}
Douglas Gregor496e8b342010-05-07 19:42:26 +0000107
108namespace PR7080 {
109 template <class T, class U>
110 class X
111 {
112 typedef char true_t;
113 class false_t { char dummy[2]; };
114 static true_t dispatch(U);
115 static false_t dispatch(...);
116 static T trigger();
117 public:
118 enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) };
119 };
120
121 template <class T>
122 class rv : public T
123 { };
124
125 bool x = X<int, rv<int>&>::value;
126}
John McCallbf8c5192010-05-27 06:40:31 +0000127
128namespace pr7199 {
129 template <class T> class A; // expected-note {{template is declared here}}
130 template <class T> class B {
131 class A<T>::C field; // expected-error {{implicit instantiation of undefined template 'pr7199::A<int>'}}
132 };
133
134 template class B<int>; // expected-note {{in instantiation}}
135}
Douglas Gregor72ebdab2010-11-13 19:36:57 +0000136
137namespace PR8425 {
138 template <typename T>
139 class BaseT {};
140
141 template <typename T>
142 class DerivedT : public BaseT<T> {};
143
144 template <typename T>
145 class FromT {
146 public:
147 operator DerivedT<T>() const { return DerivedT<T>(); }
148 };
149
150 void test() {
151 FromT<int> ft;
152 BaseT<int> bt(ft);
153 }
154}