blob: babc55217a95b34f04440596b1895c545a7d3f57 [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}