xref: /llvm-project/clang/test/SemaTemplate/instantiate-field.cpp (revision 789adec6bde00e42fddc7db5973a7834512a6acf)
18fbe78f6SDaniel Dunbar // RUN: %clang_cc1 -fsyntax-only -verify %s
21efa437bSDouglas Gregor 
31efa437bSDouglas Gregor template<typename T>
41efa437bSDouglas Gregor struct X {
51efa437bSDouglas Gregor   int x;
61efa437bSDouglas Gregor   T y; // expected-error{{data member instantiated with function type}}
71efa437bSDouglas Gregor   T* z;
81efa437bSDouglas Gregor   T bitfield : 12; // expected-error{{bit-field 'bitfield' has non-integral type 'float'}} \
91efa437bSDouglas Gregor                   // expected-error{{data member instantiated with function type}}
101efa437bSDouglas Gregor 
111efa437bSDouglas Gregor   mutable T x2; // expected-error{{data member instantiated with function type}}
121efa437bSDouglas Gregor };
131efa437bSDouglas Gregor 
test1(const X<int> * xi)141efa437bSDouglas Gregor void test1(const X<int> *xi) {
151efa437bSDouglas Gregor   int i1 = xi->x;
161efa437bSDouglas Gregor   const int &i2 = xi->y;
171efa437bSDouglas Gregor   int* ip1 = xi->z;
181efa437bSDouglas Gregor   int i3 = xi->bitfield;
191efa437bSDouglas Gregor   xi->x2 = 17;
201efa437bSDouglas Gregor }
211efa437bSDouglas Gregor 
test2(const X<float> * xf)221efa437bSDouglas Gregor void test2(const X<float> *xf) {
2385f90559SJohn McCall   (void)xf->x; // expected-note{{in instantiation of template class 'X<float>' requested here}}
241efa437bSDouglas Gregor }
251efa437bSDouglas Gregor 
test3(const X<int (int)> * xf)261efa437bSDouglas Gregor void test3(const X<int(int)> *xf) {
2785f90559SJohn McCall   (void)xf->x; // expected-note{{in instantiation of template class 'X<int (int)>' requested here}}
281efa437bSDouglas Gregor }
2917158425SDouglas Gregor 
3017158425SDouglas Gregor namespace PR7123 {
3117158425SDouglas Gregor   template <class > struct requirement_;
3217158425SDouglas Gregor 
3317158425SDouglas Gregor   template <void(*)()> struct instantiate
3417158425SDouglas Gregor   { };
3517158425SDouglas Gregor 
3617158425SDouglas Gregor   template <class > struct requirement ;
3717158425SDouglas Gregor   struct failed ;
3817158425SDouglas Gregor 
3917158425SDouglas Gregor   template <class Model> struct requirement<failed *Model::*>
4017158425SDouglas Gregor   {
failedPR7123::requirement4117158425SDouglas Gregor     static void failed()
4217158425SDouglas Gregor     {
4317158425SDouglas Gregor       ((Model*)0)->~Model(); // expected-note{{in instantiation of}}
4417158425SDouglas Gregor     }
4517158425SDouglas Gregor   };
4617158425SDouglas Gregor 
4717158425SDouglas Gregor   template <class Model> struct requirement_<void(*)(Model)> : requirement<failed *Model::*>
4817158425SDouglas Gregor   { };
4917158425SDouglas Gregor 
5017158425SDouglas Gregor   template <int> struct Requires_
5117158425SDouglas Gregor   { typedef void type; };
5217158425SDouglas Gregor 
5317158425SDouglas Gregor   template <class Model> struct usage_requirements
5417158425SDouglas Gregor   {
~usage_requirementsPR7123::usage_requirements5517158425SDouglas Gregor     ~usage_requirements()
5617158425SDouglas Gregor     {((Model*)0)->~Model(); } // expected-note{{in instantiation of}}
5717158425SDouglas Gregor   };
5817158425SDouglas Gregor 
5917158425SDouglas Gregor   template < typename TT > struct BidirectionalIterator
6017158425SDouglas Gregor   {
6117158425SDouglas Gregor     enum
6217158425SDouglas Gregor       { value = 0 };
6317158425SDouglas Gregor 
6417158425SDouglas Gregor     instantiate< requirement_<void(*)(usage_requirements<BidirectionalIterator>)>::failed> int534; // expected-note{{in instantiation of}}
6517158425SDouglas Gregor 
~BidirectionalIteratorPR7123::BidirectionalIterator6617158425SDouglas Gregor     ~BidirectionalIterator()
6717158425SDouglas Gregor     { i--; } // expected-error{{cannot decrement value of type 'PR7123::X'}}
6817158425SDouglas Gregor 
6917158425SDouglas Gregor     TT i;
7017158425SDouglas Gregor   };
7117158425SDouglas Gregor 
7217158425SDouglas Gregor   struct X
7317158425SDouglas Gregor   { };
7417158425SDouglas Gregor 
7517158425SDouglas Gregor   template<typename RanIter>
sort(RanIter,RanIter)7617158425SDouglas Gregor   typename Requires_< BidirectionalIterator<RanIter>::value >::type sort(RanIter,RanIter){}
7717158425SDouglas Gregor 
f()7817158425SDouglas Gregor   void f()
7917158425SDouglas Gregor   {
8017158425SDouglas Gregor     X x;
8117158425SDouglas Gregor     sort(x,x);
8217158425SDouglas Gregor   }
8317158425SDouglas Gregor }
8494584683SDouglas Gregor 
8594584683SDouglas Gregor namespace PR7355 {
8694584683SDouglas Gregor   template<typename T1> class A {
8794584683SDouglas Gregor     class D; // expected-note{{declared here}}
8894584683SDouglas Gregor     D d; //expected-error{{implicit instantiation of undefined member 'PR7355::A<int>::D'}}
8994584683SDouglas Gregor   };
9094584683SDouglas Gregor 
9194584683SDouglas Gregor   A<int> ai; // expected-note{{in instantiation of}}
9294584683SDouglas Gregor }
93*789adec6SDouglas Gregor 
94*789adec6SDouglas Gregor namespace PR8712 {
95*789adec6SDouglas Gregor   template <int dim>
96*789adec6SDouglas Gregor   class B {
97*789adec6SDouglas Gregor   public:
98*789adec6SDouglas Gregor     B(const unsigned char i);
99*789adec6SDouglas Gregor     unsigned char value : (dim > 0 ? dim : 1);
100*789adec6SDouglas Gregor   };
101*789adec6SDouglas Gregor 
102*789adec6SDouglas Gregor   template <int dim>
B(const unsigned char i)103*789adec6SDouglas Gregor   inline B<dim>::B(const unsigned char i) : value(i) {}
104*789adec6SDouglas Gregor }
105