blob: 0bbb3ca9c88c8b5e1898a768ef57913edf6fb1df [file] [log] [blame]
Reid Kleckner744e3e72015-10-20 21:04:13 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s
Anders Carlsson4bb87ce2009-08-29 19:37:28 +00003
John McCall80053822009-12-03 00:58:24 +00004namespace test0 {
5 namespace N { }
Douglas Gregore0b28662009-11-17 06:07:40 +00006
John McCall80053822009-12-03 00:58:24 +00007 template<typename T>
8 struct A {
9 void f();
10 };
Anders Carlsson4bb87ce2009-08-29 19:37:28 +000011
John McCall80053822009-12-03 00:58:24 +000012 template<typename T>
13 struct B : A<T> {
14 using A<T>::f;
15
16 void g() {
17 using namespace N;
18 f();
19 }
20 };
21
22 template struct B<int>;
23}
24
25namespace 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
John McCall3155f572010-04-09 19:03:51 +000042 class Knot : public JoinVisitor<Knot> {
John McCall80053822009-12-03 00:58:24 +000043 };
44
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}}
Anders Carlsson4bb87ce2009-08-29 19:37:28 +000049 }
John McCall80053822009-12-03 00:58:24 +000050}
John McCalla1d85502009-12-22 22:26:37 +000051
52// PR5847
53namespace test2 {
54 namespace ns {
55 void foo();
56 }
57
58 template <class T> void bar(T* ptr) {
59 using ns::foo;
60 foo();
61 }
62
63 template void bar(char *);
64}
Douglas Gregorac2e4302010-09-29 17:58:28 +000065
66namespace 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
77 void f2()
78 {
79 t<int>::s2 a;
80 t<int>::s2 const & b = a;
81 b.f1();
82 }
83}
Eli Friedman0eaf10b2013-08-20 00:39:40 +000084
85namespace 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
98 void f() {
99 access(0);
100 }
101 };
102
103 void f() {
104 X<int> x;
105 x.f();
106 }
107}
Reid Kleckner744e3e72015-10-20 21:04:13 +0000108
109namespace pr21923 {
110template <typename> struct Base {
111 int field;
112 void method();
113};
114template <typename Scalar> struct Derived : Base<Scalar> {
115 using Base<Scalar>::field;
116 using Base<Scalar>::method;
117 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
145template 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.
150struct 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>
158 void instance_method() { (void)maybe_static<T>(); }
159 template <typename T>
160 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};
165void force_instantiation(UnresolvedTemplateNames x) {
166 x.instance_method<int>();
167 UnresolvedTemplateNames::static_method<int>(); // expected-note {{requested here}}
168}
169} // pr21923