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