Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 2 | |
| 3 | template<typename T> |
| 4 | struct X { |
| 5 | int x; |
| 6 | T y; // expected-error{{data member instantiated with function type}} |
| 7 | T* z; |
| 8 | T bitfield : 12; // expected-error{{bit-field 'bitfield' has non-integral type 'float'}} \ |
| 9 | // expected-error{{data member instantiated with function type}} |
| 10 | |
| 11 | mutable T x2; // expected-error{{data member instantiated with function type}} |
| 12 | }; |
| 13 | |
| 14 | void test1(const X<int> *xi) { |
| 15 | int i1 = xi->x; |
| 16 | const int &i2 = xi->y; |
| 17 | int* ip1 = xi->z; |
| 18 | int i3 = xi->bitfield; |
| 19 | xi->x2 = 17; |
| 20 | } |
| 21 | |
| 22 | void test2(const X<float> *xf) { |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 23 | (void)xf->x; // expected-note{{in instantiation of template class 'X<float>' requested here}} |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | void test3(const X<int(int)> *xf) { |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 27 | (void)xf->x; // expected-note{{in instantiation of template class 'X<int (int)>' requested here}} |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 28 | } |
Douglas Gregor | 9679caf | 2010-05-12 17:27:19 +0000 | [diff] [blame] | 29 | |
| 30 | namespace PR7123 { |
| 31 | template <class > struct requirement_; |
| 32 | |
| 33 | template <void(*)()> struct instantiate |
| 34 | { }; |
| 35 | |
| 36 | template <class > struct requirement ; |
| 37 | struct failed ; |
| 38 | |
| 39 | template <class Model> struct requirement<failed *Model::*> |
| 40 | { |
| 41 | static void failed() |
| 42 | { |
| 43 | ((Model*)0)->~Model(); // expected-note{{in instantiation of}} |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | template <class Model> struct requirement_<void(*)(Model)> : requirement<failed *Model::*> |
| 48 | { }; |
| 49 | |
| 50 | template <int> struct Requires_ |
| 51 | { typedef void type; }; |
| 52 | |
| 53 | template <class Model> struct usage_requirements |
| 54 | { |
| 55 | ~usage_requirements() |
| 56 | {((Model*)0)->~Model(); } // expected-note{{in instantiation of}} |
| 57 | }; |
| 58 | |
| 59 | template < typename TT > struct BidirectionalIterator |
| 60 | { |
| 61 | enum |
| 62 | { value = 0 }; |
| 63 | |
| 64 | instantiate< requirement_<void(*)(usage_requirements<BidirectionalIterator>)>::failed> int534; // expected-note{{in instantiation of}} |
| 65 | |
| 66 | ~BidirectionalIterator() |
| 67 | { i--; } // expected-error{{cannot decrement value of type 'PR7123::X'}} |
| 68 | |
| 69 | TT i; |
| 70 | }; |
| 71 | |
| 72 | struct X |
| 73 | { }; |
| 74 | |
| 75 | template<typename RanIter> |
| 76 | typename Requires_< BidirectionalIterator<RanIter>::value >::type sort(RanIter,RanIter){} |
| 77 | |
| 78 | void f() |
| 79 | { |
| 80 | X x; |
| 81 | sort(x,x); |
| 82 | } |
| 83 | } |
Douglas Gregor | d27e50c | 2010-06-16 16:54:04 +0000 | [diff] [blame^] | 84 | |
| 85 | namespace PR7355 { |
| 86 | template<typename T1> class A { |
| 87 | class D; // expected-note{{declared here}} |
| 88 | D d; //expected-error{{implicit instantiation of undefined member 'PR7355::A<int>::D'}} |
| 89 | }; |
| 90 | |
| 91 | A<int> ai; // expected-note{{in instantiation of}} |
| 92 | } |