blob: 507894a2ff691ab40a24114b9c7ac78179b9534f [file] [log] [blame]
Douglas Gregore7450f52009-03-24 19:52:54 +00001// RUN: clang-cc -fsyntax-only -verify %s
2
3// Tests various places where requiring a complete type involves
4// instantiation of that type.
5
6template<typename T>
7struct X {
8 X(T);
9
10 T f; // expected-error{{data member instantiated with function type 'float (int)'}} \
11 // expected-error{{data member instantiated with function type 'int (int)'}} \
12 // expected-error{{data member instantiated with function type 'char (char)'}} \
13 // expected-error{{data member instantiated with function type 'short (short)'}} \
Douglas Gregor3f5b61c2009-05-14 00:28:11 +000014 // expected-error{{data member instantiated with function type 'float (float)'}}
Douglas Gregore7450f52009-03-24 19:52:54 +000015};
16
17X<int> f() { return 0; }
18
19struct XField {
20 X<float(int)> xf; // expected-note{{in instantiation of template class 'struct X<float (int)>' requested here}}
21};
22
23void test_subscript(X<double> *ptr1, X<int(int)> *ptr2, int i) {
24 (void)ptr1[i];
25 (void)ptr2[i]; // expected-note{{in instantiation of template class 'struct X<int (int)>' requested here}}
26}
27
28void test_arith(X<signed char> *ptr1, X<unsigned char> *ptr2,
29 X<char(char)> *ptr3, X<short(short)> *ptr4) {
30 (void)(ptr1 + 5);
31 // FIXME: if I drop the ')' after void, below, it still parses (!)
32 (void)(5 + ptr2);
33 (void)(ptr3 + 5); // expected-note{{in instantiation of template class 'struct X<char (char)>' requested here}}
34 (void)(5 + ptr4); // expected-note{{in instantiation of template class 'struct X<short (short)>' requested here}}
35}
36
37void test_new() {
38 (void)new X<float>(0);
39 (void)new X<float(float)>; // expected-note{{in instantiation of template class 'struct X<float (float)>' requested here}}
40}
41
42void test_memptr(X<long> *p1, long X<long>::*pm1,
Douglas Gregor3f5b61c2009-05-14 00:28:11 +000043 X<long(long)> *p2,
44 long (X<long(long)>::*pm2)(long)) {
Douglas Gregore7450f52009-03-24 19:52:54 +000045 (void)(p1->*pm1);
Douglas Gregor3f5b61c2009-05-14 00:28:11 +000046 (void)((p2->*pm2)(0));
Douglas Gregore7450f52009-03-24 19:52:54 +000047}
Douglas Gregor393896f2009-11-05 13:06:35 +000048
49// Reference binding to a base
50template<typename T>
51struct X1 { };
52
53template<typename T>
54struct X2 : public T { };
55
56void refbind_base(X2<X1<int> > &x2) {
57 X1<int> &x1 = x2;
58}
59
60// Enumerate constructors for user-defined conversion.
61template<typename T>
62struct X3 {
63 X3(T);
64};
65
66void enum_constructors(X1<float> &x1) {
67 X3<X1<float> > x3 = x1;
68}