1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s
3 
4 namespace test0 {
5   namespace N { }
6 
7   template<typename T>
8   struct A {
9     void f();
10   };
11 
12   template<typename T>
13   struct B : A<T> {
14     using A<T>::f;
15 
gtest0::B16     void g() {
17       using namespace N;
18       f();
19     }
20   };
21 
22   template struct B<int>;
23 }
24 
25 namespace test1 {
26   template <class Derived> struct Visitor1 {
27     void Visit(struct Object1*);
28   };
29   template <class Derived> struct Visitor2 {
30     void Visit(struct Object2*); // expected-note {{candidate function}}
31   };
32 
33   template <class Derived> struct JoinVisitor
34       : Visitor1<Derived>, Visitor2<Derived> {
35     typedef Visitor1<Derived> Base1;
36     typedef Visitor2<Derived> Base2;
37 
38     void Visit(struct Object1*);  // expected-note {{candidate function}}
39     using Base2::Visit;
40   };
41 
42   class Knot : public JoinVisitor<Knot> {
43   };
44 
test()45   void test() {
46     Knot().Visit((struct Object1*) 0);
47     Knot().Visit((struct Object2*) 0);
48     Knot().Visit((struct Object3*) 0); // expected-error {{no matching member function for call}}
49   }
50 }
51 
52 // PR5847
53 namespace test2 {
54   namespace ns {
55     void foo();
56   }
57 
bar(T * ptr)58   template <class T> void bar(T* ptr) {
59     using ns::foo;
60     foo();
61   }
62 
63   template void bar(char *);
64 }
65 
66 namespace test3 {
67   template <typename T> struct t {
68     struct s1 {
69       T f1() const;
70     };
71     struct s2 : s1 {
72       using s1::f1;
73       T f1() const;
74     };
75   };
76 
f2()77   void f2()
78   {
79     t<int>::s2 a;
80     t<int>::s2 const & b = a;
81     b.f1();
82   }
83 }
84 
85 namespace PR16936 {
86   // Make sure both using decls are properly considered for
87   // overload resolution.
88   template<class> struct A {
89     void access(int);
90   };
91   template<class> struct B {
92     void access();
93   };
94   template<class CELL> struct X : public A<CELL>, public B<CELL> {
95     using A<CELL>::access;
96     using B<CELL>::access;
97 
fPR16936::X98     void f() {
99       access(0);
100     }
101   };
102 
f()103   void f() {
104     X<int> x;
105     x.f();
106   }
107 }
108 
109 namespace pr21923 {
110 template <typename> struct Base {
111   int field;
112   void method();
113 };
114 template <typename Scalar> struct Derived : Base<Scalar> {
115   using Base<Scalar>::field;
116   using Base<Scalar>::method;
m_fn1pr21923::Derived117   static void m_fn1() {
118     // expected-error@+1 {{invalid use of member 'field' in static member function}}
119     (void)field;
120     // expected-error@+1 {{invalid use of member 'field' in static member function}}
121     (void)&field;
122     // expected-error@+1 {{call to non-static member function without an object argument}}
123     (void)method;
124     // expected-error@+1 {{call to non-static member function without an object argument}}
125     (void)&method;
126     // expected-error@+1 {{call to non-static member function without an object argument}}
127     method();
128     (void)&Base<Scalar>::field;
129     (void)&Base<Scalar>::method;
130   }
131 #if __cplusplus >= 201103L
132   // These usages are OK in C++11 due to the unevaluated context.
133   enum { TheSize = sizeof(field) };
134   typedef decltype(field) U;
135 #else
136   // expected-error@+1 {{invalid use of non-static data member 'field'}}
137   enum { TheSize = sizeof(field) };
138 #endif
139 };
140 
141 #if __cplusplus < 201103L
142 // C++98 has an extra note for TheSize.
143 // expected-note@+2 {{requested here}}
144 #endif
145 template class Derived<int>; // expected-note {{requested here}}
146 
147 // This is interesting because we form an UnresolvedLookupExpr in the static
148 // function template and an UnresolvedMemberExpr in the instance function
149 // template. As a result, we get slightly different behavior.
150 struct UnresolvedTemplateNames {
151   template <typename> void maybe_static();
152 #if __cplusplus < 201103L
153   // expected-warning@+2 {{default template arguments for a function template are a C++11 extension}}
154 #endif
155   template <typename T, typename T::type = 0> static void maybe_static();
156 
157   template <typename T>
instance_methodpr21923::UnresolvedTemplateNames158   void instance_method() { (void)maybe_static<T>(); }
159   template <typename T>
static_methodpr21923::UnresolvedTemplateNames160   static void static_method() {
161     // expected-error@+1 {{call to non-static member function without an object argument}}
162     (void)maybe_static<T>();
163   }
164 };
force_instantiation(UnresolvedTemplateNames x)165 void force_instantiation(UnresolvedTemplateNames x) {
166   x.instance_method<int>();
167   UnresolvedTemplateNames::static_method<int>(); // expected-note {{requested here}}
168 }
169 } // pr21923
170