member-template-access-expr.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename U, typename T>
  3. U f0(T t) {
  4. return t.template get<U>();
  5. }
  6. template<typename U, typename T>
  7. int &f1(T t) {
  8. // FIXME: When we pretty-print this, we lose the "template" keyword.
  9. return t.U::template get<int&>();
  10. }
  11. struct X {
  12. template<typename T> T get();
  13. };
  14. void test_f0(X x) {
  15. int i = f0<int>(x);
  16. int &ir = f0<int&>(x);
  17. }
  18. struct XDerived : public X {
  19. };
  20. void test_f1(XDerived xd) {
  21. int &ir = f1<X>(xd);
  22. }
  23. // PR5213
  24. template <class T>
  25. struct A {};
  26. template<class T>
  27. class B
  28. {
  29. A<T> a_;
  30. public:
  31. void destroy();
  32. };
  33. template<class T>
  34. void
  35. B<T>::destroy()
  36. {
  37. a_.~A<T>();
  38. }
  39. void do_destroy_B(B<int> b) {
  40. b.destroy();
  41. }
  42. struct X1 {
  43. int* f1(int);
  44. template<typename T> float* f1(T);
  45. static int* f2(int);
  46. template<typename T> static float* f2(T);
  47. };
  48. void test_X1(X1 x1) {
  49. float *fp1 = x1.f1<>(17);
  50. float *fp2 = x1.f1<int>(3.14); // expected-warning {{implicit conversion from 'double' to 'int' changes value from 3.14 to 3}}
  51. int *ip1 = x1.f1(17);
  52. float *ip2 = x1.f1(3.14);
  53. float* (X1::*mf1)(int) = &X1::f1;
  54. float* (X1::*mf2)(int) = &X1::f1<>;
  55. float* (X1::*mf3)(float) = &X1::f1<float>;
  56. float* (*fp3)(int) = &X1::f2;
  57. float* (*fp4)(int) = &X1::f2<>;
  58. float* (*fp5)(float) = &X1::f2<float>;
  59. float* (*fp6)(int) = X1::f2;
  60. float* (*fp7)(int) = X1::f2<>;
  61. float* (*fp8)(float) = X1::f2<float>;
  62. }
  63. template<int A> struct X2 {
  64. int m;
  65. };
  66. template<typename T>
  67. struct X3 : T { };
  68. template<typename T>
  69. struct X4 {
  70. template<typename U>
  71. void f(X2<sizeof(X3<U>().U::m)>);
  72. };
  73. void f(X4<X3<int> > x4i) {
  74. X2<sizeof(int)> x2;
  75. x4i.f<X2<sizeof(int)> >(x2);
  76. }
  77. template<typename T>
  78. struct X5 {
  79. template<typename U>
  80. void f();
  81. void g() {
  82. this->f<T*>();
  83. }
  84. };
  85. namespace PR6021 {
  86. template< class T1, class T2 >
  87. class Outer
  88. {
  89. public: // Range operations
  90. template< class X > X tmpl( const X* = 0 ) const;
  91. struct Inner
  92. {
  93. const Outer& o;
  94. template< class X >
  95. operator X() const
  96. {
  97. return o.tmpl<X>();
  98. }
  99. };
  100. };
  101. }
  102. namespace rdar8198511 {
  103. template<int, typename U>
  104. struct Base {
  105. void f();
  106. };
  107. template<typename T>
  108. struct X0 : Base<1, T> { };
  109. template<typename T>
  110. struct X1 {
  111. X0<int> x0;
  112. void f() {
  113. this->x0.Base<1, int>::f();
  114. }
  115. };
  116. }