xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/using-decl-templates.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc template<typename T> struct A {
fA4*f4a2713aSLionel Sambuc   void f() { }
5*f4a2713aSLionel Sambuc   struct N { }; // expected-note{{target of using declaration}}
6*f4a2713aSLionel Sambuc };
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc template<typename T> struct B : A<T> {
9*f4a2713aSLionel Sambuc   using A<T>::f;
10*f4a2713aSLionel Sambuc   using A<T>::N; // expected-error{{dependent using declaration resolved to type without 'typename'}}
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc   using A<T>::foo; // expected-error{{no member named 'foo'}}
13*f4a2713aSLionel Sambuc   using A<double>::f; // expected-error{{using declaration refers into 'A<double>::', which is not a base class of 'B<int>'}}
14*f4a2713aSLionel Sambuc };
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc B<int> a; // expected-note{{in instantiation of template class 'B<int>' requested here}}
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc template<typename T> struct C : A<T> {
19*f4a2713aSLionel Sambuc   using A<T>::f;
20*f4a2713aSLionel Sambuc 
fC21*f4a2713aSLionel Sambuc   void f() { };
22*f4a2713aSLionel Sambuc };
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc template <typename T> struct D : A<T> {
25*f4a2713aSLionel Sambuc   using A<T>::f;
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc   void f();
28*f4a2713aSLionel Sambuc };
29*f4a2713aSLionel Sambuc 
f()30*f4a2713aSLionel Sambuc template<typename T> void D<T>::f() { }
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc template<typename T> struct E : A<T> {
33*f4a2713aSLionel Sambuc   using A<T>::f;
34*f4a2713aSLionel Sambuc 
gE35*f4a2713aSLionel Sambuc   void g() { f(); }
36*f4a2713aSLionel Sambuc };
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc namespace test0 {
39*f4a2713aSLionel Sambuc   struct Base {
40*f4a2713aSLionel Sambuc     int foo;
41*f4a2713aSLionel Sambuc   };
42*f4a2713aSLionel Sambuc   template<typename T> struct E : Base {
43*f4a2713aSLionel Sambuc     using Base::foo;
44*f4a2713aSLionel Sambuc   };
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc   template struct E<int>;
47*f4a2713aSLionel Sambuc }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc // PR7896
50*f4a2713aSLionel Sambuc namespace PR7896 {
51*f4a2713aSLionel Sambuc template <class T> struct Foo {
52*f4a2713aSLionel Sambuc   int k (float);
53*f4a2713aSLionel Sambuc };
54*f4a2713aSLionel Sambuc struct Baz {
55*f4a2713aSLionel Sambuc   int k (int);
56*f4a2713aSLionel Sambuc };
57*f4a2713aSLionel Sambuc template <class T> struct Bar : public Foo<T>, Baz {
58*f4a2713aSLionel Sambuc   using Foo<T>::k;
59*f4a2713aSLionel Sambuc   using Baz::k;
fooPR7896::Bar60*f4a2713aSLionel Sambuc   int foo() {
61*f4a2713aSLionel Sambuc     return k (1.0f);
62*f4a2713aSLionel Sambuc   }
63*f4a2713aSLionel Sambuc };
64*f4a2713aSLionel Sambuc template int Bar<int>::foo();
65*f4a2713aSLionel Sambuc }
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc // PR10883
68*f4a2713aSLionel Sambuc namespace PR10883 {
69*f4a2713aSLionel Sambuc   template <typename T>
70*f4a2713aSLionel Sambuc   class Base {
71*f4a2713aSLionel Sambuc    public:
72*f4a2713aSLionel Sambuc     typedef long Container;
73*f4a2713aSLionel Sambuc   };
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc   template <typename T>
76*f4a2713aSLionel Sambuc   class Derived : public Base<T> {
77*f4a2713aSLionel Sambuc    public:
78*f4a2713aSLionel Sambuc     using Base<T>::Container;
79*f4a2713aSLionel Sambuc 
80*f4a2713aSLionel Sambuc     void foo(const Container& current); // expected-error {{unknown type name 'Container'}}
81*f4a2713aSLionel Sambuc   };
82*f4a2713aSLionel Sambuc }
83*f4a2713aSLionel Sambuc 
84*f4a2713aSLionel Sambuc template<typename T> class UsingTypenameNNS {
85*f4a2713aSLionel Sambuc   using typename T::X;
86*f4a2713aSLionel Sambuc   typename X::X x;
87*f4a2713aSLionel Sambuc };
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc namespace aliastemplateinst {
90*f4a2713aSLionel Sambuc   template<typename T> struct A { };
91*f4a2713aSLionel Sambuc   template<typename T> using APtr = A<T*>; // expected-note{{previous use is here}}
92*f4a2713aSLionel Sambuc 
93*f4a2713aSLionel Sambuc   template struct APtr<int>; // expected-error{{elaborated type refers to a non-tag type}}
94*f4a2713aSLionel Sambuc }
95