blob: 183fefab4116e17cfbc1440fdc698cb4a8c019ca [file] [log] [blame]
Shih-wei Liaof8fd82b2010-02-10 11:10:31 -08001// RUN: %clang_cc1 -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)'}} \
14 // expected-error{{data member instantiated with function type 'float (float)'}}
15};
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,
43 X<long(long)> *p2,
44 long (X<long(long)>::*pm2)(long)) {
45 (void)(p1->*pm1);
46 (void)((p2->*pm2)(0));
47}
48
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}