instantiate-field.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T>
  3. struct X {
  4. int x;
  5. T y; // expected-error{{data member instantiated with function type}}
  6. T* z;
  7. T bitfield : 12; // expected-error{{bit-field 'bitfield' has non-integral type 'float'}} \
  8. // expected-error{{data member instantiated with function type}}
  9. mutable T x2; // expected-error{{data member instantiated with function type}}
  10. };
  11. void test1(const X<int> *xi) {
  12. int i1 = xi->x;
  13. const int &i2 = xi->y;
  14. int* ip1 = xi->z;
  15. int i3 = xi->bitfield;
  16. xi->x2 = 17;
  17. }
  18. void test2(const X<float> *xf) {
  19. (void)xf->x; // expected-note{{in instantiation of template class 'X<float>' requested here}}
  20. }
  21. void test3(const X<int(int)> *xf) {
  22. (void)xf->x; // expected-note{{in instantiation of template class 'X<int (int)>' requested here}}
  23. }
  24. namespace PR7123 {
  25. template <class > struct requirement_;
  26. template <void(*)()> struct instantiate
  27. { };
  28. template <class > struct requirement ;
  29. struct failed ;
  30. template <class Model> struct requirement<failed *Model::*>
  31. {
  32. static void failed()
  33. {
  34. ((Model*)0)->~Model(); // expected-note{{in instantiation of}}
  35. }
  36. };
  37. template <class Model> struct requirement_<void(*)(Model)> : requirement<failed *Model::*>
  38. { };
  39. template <int> struct Requires_
  40. { typedef void type; };
  41. template <class Model> struct usage_requirements
  42. {
  43. ~usage_requirements()
  44. {((Model*)0)->~Model(); } // expected-note{{in instantiation of}}
  45. };
  46. template < typename TT > struct BidirectionalIterator
  47. {
  48. enum
  49. { value = 0 };
  50. instantiate< requirement_<void(*)(usage_requirements<BidirectionalIterator>)>::failed> int534; // expected-note{{in instantiation of}}
  51. ~BidirectionalIterator()
  52. { i--; } // expected-error{{cannot decrement value of type 'PR7123::X'}}
  53. TT i;
  54. };
  55. struct X
  56. { };
  57. template<typename RanIter>
  58. typename Requires_< BidirectionalIterator<RanIter>::value >::type sort(RanIter,RanIter){}
  59. void f()
  60. {
  61. X x;
  62. sort(x,x);
  63. }
  64. }
  65. namespace PR7355 {
  66. template<typename T1> class A {
  67. class D; // expected-note{{declared here}}
  68. D d; //expected-error{{implicit instantiation of undefined member 'PR7355::A<int>::D'}}
  69. };
  70. A<int> ai; // expected-note{{in instantiation of}}
  71. }
  72. namespace PR8712 {
  73. template <int dim>
  74. class B {
  75. public:
  76. B(const unsigned char i);
  77. unsigned char value : (dim > 0 ? dim : 1);
  78. };
  79. template <int dim>
  80. inline B<dim>::B(const unsigned char i) : value(i) {}
  81. }