• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
3 
4 extern "C" { void f(bool); }
5 
6 namespace std {
7   using ::f;
f()8   inline void f() { return f(true); }
9 }
10 
11 namespace M {
12   void f(float);
13 }
14 
15 namespace N {
16   using M::f;
f(int)17   void f(int) { } // expected-note{{previous}}
18 
f(int)19   void f(int) { } // expected-error{{redefinition}}
20 }
21 
22 namespace N {
23   void f(double);
24   void f(long);
25 }
26 
27 struct X0 {
28   void operator()(int);
29   void operator()(long);
30 };
31 
32 struct X1 : X0 {
33   // FIXME: give this operator() a 'float' parameter to test overloading
34   // behavior. It currently fails.
35   void operator()();
36   using X0::operator();
37 
testX138   void test() {
39     (*this)(1);
40   }
41 };
42 
43 struct A { void f(); };
44 struct B : A { };
45 class C : B { using B::f; };
46 
47 // PR5751: Resolve overloaded functions through using decls.
48 namespace O {
49   void f(int i);
50   void f(double d);
51 }
52 namespace P {
53   void f();
54   void g(void (*ptr)(int));
55   using O::f;
test()56   void test() {
57     f();
58     f(1);
59     void (*f_ptr1)(double) = f;
60     void (*f_ptr2)() = f;
61     g(f);
62   }
63 }
64 
65 // Make sure that ADL can find names brought in by using decls.
66 namespace test0 {
67   namespace ns {
68     class Foo {};
69 
70     namespace inner {
71       void foo(char *); // expected-note {{no known conversion}}
72     }
73 
74     using inner::foo;
75   }
76 
test(ns::Foo * p)77   void test(ns::Foo *p) {
78     foo(*p); // expected-error {{no matching function for call to 'foo'}}
79   }
80 }
81 
82 // Redeclarations!
83 namespace test1 {
84   namespace ns0 { struct Foo {}; }
85   namespace A { void foo(ns0::Foo *p, int y, int z); }
86   namespace ns2 { using A::foo; }
87   namespace ns1 { struct Bar : ns0::Foo {}; }
88   namespace A { void foo(ns0::Foo *p, int y, int z = 0); } // expected-note {{candidate}}
89   namespace ns1 { using A::foo; }
90   namespace ns2 { struct Baz : ns1::Bar {}; }
91   namespace A { void foo(ns0::Foo *p, int y = 0, int z); }
92 
test(ns2::Baz * p)93   void test(ns2::Baz *p) {
94     foo(p, 0, 0); // okay!
95     foo(p, 0); // should be fine!
96     foo(p); // expected-error {{no matching function}}
97   }
98 }
99 
100 namespace test2 {
101   namespace ns { int foo; }
102   template <class T> using ns::foo; // expected-error {{cannot template a using declaration}}
103 
104   // PR8022
105   struct A {
106     template <typename T> void f(T);
107   };
108   class B : A {
109     template <typename T> using A::f<T>; // expected-error {{cannot template a using declaration}}
110   };
111 }
112 
113 // PR8756
114 namespace foo
115 {
116   class Class1; // expected-note{{forward declaration}}
117   class Class2
118   {
119     using ::foo::Class1::Function; // expected-error{{incomplete type 'foo::Class1' named in nested name specifier}}
120   };
121 }
122 
123 // Don't suggest non-typenames for positions requiring typenames.
124 namespace using_suggestion_tyname_val {
FFF()125 namespace N { void FFF() {} }
126 using typename N::FFG; // expected-error {{no member named 'FFG' in namespace 'using_suggestion_tyname_val::N'}}
127 }
128 
129 namespace using_suggestion_member_tyname_val {
AAA()130 class CCC { public: void AAA() { } };
131 class DDD : public CCC { public: using typename CCC::AAB; }; // expected-error {{no member named 'AAB' in 'using_suggestion_member_tyname_val::CCC'}}
132 }
133 
134 namespace using_suggestion_tyname_val_dropped_specifier {
FFF()135 void FFF() {}
136 namespace N { }
137 using typename N::FFG; // expected-error {{no member named 'FFG' in namespace 'using_suggestion_tyname_val_dropped_specifier::N'}}
138 }
139 
140 // Currently hints aren't provided to drop out the incorrect M::.
141 namespace using_suggestion_ty_dropped_nested_specifier {
142 namespace N {
143 class AAA {}; // expected-note {{'N::AAA' declared here}}
144 namespace M { }
145 }
146 using N::M::AAA; // expected-error {{no member named 'AAA' in namespace 'using_suggestion_ty_dropped_nested_specifier::N::M'; did you mean 'N::AAA'?}}
147 }
148 
149 namespace using_suggestion_tyname_ty_dropped_nested_specifier {
150 namespace N {
151 class AAA {}; // expected-note {{'N::AAA' declared here}}
152 namespace M { }
153 }
154 using typename N::M::AAA; // expected-error {{no member named 'AAA' in namespace 'using_suggestion_tyname_ty_dropped_nested_specifier::N::M'; did you mean 'N::AAA'?}}
155 }
156 
157 namespace using_suggestion_val_dropped_nested_specifier {
158 namespace N {
FFF()159 void FFF() {} // expected-note {{'N::FFF' declared here}}
160 namespace M { }
161 }
162 using N::M::FFF; // expected-error {{no member named 'FFF' in namespace 'using_suggestion_val_dropped_nested_specifier::N::M'; did you mean 'N::FFF'?}}
163 }
164 
165 namespace UsingDeclVsHiddenName {
166   namespace A {
167     enum HiddenTag1 {}; // expected-note {{previous use is here}}
168     enum HiddenTag2 {}; // expected-note {{target}}
169     int HiddenFn1; // expected-note {{target}}
170     int HiddenFn2; // expected-note {{target}}
171     int HiddenLocalExtern1;
172     int HiddenLocalExtern2;
173   }
174 
175   namespace B {
176     using A::HiddenTag1;
177     using A::HiddenFn1; // expected-note {{using declaration}}
178     using A::HiddenLocalExtern1;
179 
180     struct S {
181       friend struct HiddenTag1; // expected-error {{tag type that does not match previous}}
182       friend struct HiddenTag2; // expected-note {{conflicting declaration}}
183       friend void HiddenFn1(); // expected-error {{cannot befriend target of using declaration}}
184       friend void HiddenFn2(); // expected-note {{conflicting declaration}}
fUsingDeclVsHiddenName::B::S185       void f() {
186         // OK, these are not in the scope of namespace B, even though they're
187         // members of the namespace.
188         void HiddenLocalExtern1();
189         void HiddenLocalExtern2();
190       }
191     };
192 
193     using A::HiddenTag2; // expected-error {{conflicts with declaration already in scope}}
194     using A::HiddenFn2; // expected-error {{conflicts with declaration already in scope}}
195     using A::HiddenLocalExtern2;
196   }
197 }
198 
199 namespace PR19171 {
200   struct Z {
201     Z();
202   };
203 
204   typedef struct {
205     Z i;
206   } S;
207 
208   struct Y : S {
209     using S::S;
210 #if __cplusplus < 201103L
211     // expected-error@-2 {{no member named 'S' in 'PR19171::S'}}
212 #endif
213   };
214 
215   // [namespace.udecl]p3: In a using-declaration used as a member-declaration,
216   // the nested-name-specifier shall name a base class of the class being defined.
217   // If such a using-declaration names a constructor, the nested-name-specifier
218   // shall name a direct base class of the class being defined;
219 
220   struct B_blah { };
221   struct C_blah : B_blah { C_blah(int); }; // expected-note 0-1{{declared here}}
222   struct D1 : C_blah {
223     // FIXME: We should be able to correct this in C++11 mode.
224     using B_blah::C_blah; // expected-error-re {{no member named 'C_blah' in 'PR19171::B_blah'{{$}}}}
225   };
226   struct D2 : C_blah {
227     // Somewhat bizarrely, this names the injected-class-name of B_blah within
228     // C_blah, and is valid.
229     using C_blah::B_blah;
230   };
231   struct D3 : C_blah {
232     using C_blah::D_blah;
233 #if __cplusplus < 201103L
234     // expected-error-re@-2 {{no member named 'D_blah' in 'PR19171::C_blah'{{$}}}}
235 #else
236     // expected-error@-4 {{no member named 'D_blah' in 'PR19171::C_blah'; did you mean 'C_blah'?}}
237 #endif
238   };
239 #if __cplusplus >= 201103L
240   D3 d3(0); // ok
241 #endif
242 
243   struct E { };
244   struct EE { int EE; };
245   struct F : E {
246     using E::EE; // expected-error-re {{no member named 'EE' in 'PR19171::E'{{$}}}}
247   };
248 }
249 
250 namespace TypoCorrectTemplateMember {
251   struct A {
252     template<typename T> void foobar(T); // expected-note {{'foobar' declared here}}
253   };
254   struct B : A {
255     using A::goobar; // expected-error {{no member named 'goobar' in 'TypoCorrectTemplateMember::A'; did you mean 'foobar'?}}
256   };
257 }
258 
259 namespace use_instance_in_static {
260 struct A { int n; };
261 struct B : A {
262   using A::n;
fuse_instance_in_static::B263   static int f() { return n; } // expected-error {{invalid use of member 'n' in static member function}}
264 };
265 }
266