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