dependent-base-classes.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T, typename U>
  3. struct X0 : T::template apply<U> {
  4. X0(U u) : T::template apply<U>(u) { }
  5. };
  6. template<typename T, typename U>
  7. struct X1 : T::apply<U> { }; // expected-error{{use 'template' keyword to treat 'apply' as a dependent template name}}
  8. template<typename T>
  9. struct X2 : vector<T> { }; // expected-error{{unknown template name 'vector'}}
  10. namespace PR6031 {
  11. template<typename T>
  12. struct A;
  13. template <class X>
  14. struct C { };
  15. template <class TT>
  16. struct II {
  17. typedef typename A<TT>::type type;
  18. };
  19. template <class TT>
  20. struct FI : II<TT>
  21. {
  22. C<typename FI::type> a;
  23. };
  24. template <class TT>
  25. struct FI2
  26. {
  27. C<typename FI2::type> a; // expected-error{{no type named 'type' in 'FI2<TT>'}}
  28. };
  29. template<typename T>
  30. struct Base {
  31. class Nested { };
  32. template<typename U> struct MemberTemplate { };
  33. int a;
  34. };
  35. template<typename T>
  36. struct HasDepBase : Base<T> {
  37. int foo() {
  38. class HasDepBase::Nested nested;
  39. typedef typename HasDepBase::template MemberTemplate<T>::type type;
  40. return HasDepBase::a;
  41. }
  42. };
  43. template<typename T>
  44. struct NoDepBase {
  45. int foo() {
  46. class NoDepBase::Nested nested; // expected-error{{no class named 'Nested' in 'NoDepBase<T>'}}
  47. typedef typename NoDepBase::template MemberTemplate<T>::type type; // expected-error{{'MemberTemplate' following the 'template' keyword does not refer to a template}} \
  48. // FIXME: expected-error{{unqualified-id}}
  49. return NoDepBase::a; // expected-error{{no member named 'a' in 'NoDepBase<T>'}}
  50. }
  51. };
  52. }
  53. namespace Ambig {
  54. template<typename T>
  55. struct Base1 {
  56. typedef int type; // expected-note{{member found by ambiguous name lookup}}
  57. };
  58. struct Base2 {
  59. typedef float type; // expected-note{{member found by ambiguous name lookup}}
  60. };
  61. template<typename T>
  62. struct Derived : Base1<T>, Base2 {
  63. typedef typename Derived::type type; // expected-error{{member 'type' found in multiple base classes of different types}}
  64. type *foo(float *fp) { return fp; }
  65. };
  66. Derived<int> di; // expected-note{{instantiation of}}
  67. }
  68. namespace PR6081 {
  69. template<typename T>
  70. struct A { };
  71. template<typename T>
  72. class B : public A<T>
  73. {
  74. public:
  75. template< class X >
  76. void f0(const X & k)
  77. {
  78. this->template f1<int>()(k);
  79. }
  80. };
  81. template<typename T>
  82. class C
  83. {
  84. public:
  85. template< class X >
  86. void f0(const X & k)
  87. {
  88. this->template f1<int>()(k); // expected-error{{'f1' following the 'template' keyword does not refer to a template}} \
  89. // FIXME: expected-error{{unqualified-id}} \
  90. // expected-error{{function-style cast or type construction}} \
  91. // expected-error{{expected expression}}
  92. }
  93. };
  94. }
  95. namespace PR6413 {
  96. template <typename T> class Base_A { };
  97. class Base_B { };
  98. template <typename T>
  99. class Derived
  100. : public virtual Base_A<T>
  101. , public virtual Base_B
  102. { };
  103. }
  104. namespace PR5812 {
  105. template <class T> struct Base {
  106. Base* p;
  107. };
  108. template <class T> struct Derived: public Base<T> {
  109. typename Derived::Base* p; // meaning Derived::Base<T>
  110. };
  111. Derived<int> di;
  112. }