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