1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4 extern "C" { void f(bool); }
8 inline void f() { return f(true); }
17 void f(int) { } // expected-note{{previous}}
19 void f(int) { } // expected-error{{redefinition}}
29 void operator()(long);
33 void operator()(float&);
41 struct A
{ void f(); };
43 class C
: B
{ using B::f
; };
45 // PR5751: Resolve overloaded functions through using decls.
52 void g(void (*ptr
)(int));
57 void (*f_ptr1
)(double) = f
;
63 // Make sure that ADL can find names brought in by using decls.
69 void foo(char *); // expected-note {{no known conversion}}
75 void test(ns::Foo
*p
) {
76 foo(*p
); // expected-error {{no matching function for call to 'foo'}}
82 namespace ns0
{ struct Foo
{}; }
83 namespace A
{ void foo(ns0::Foo
*p
, int y
, int z
); }
84 namespace ns2
{ using A::foo
; }
85 namespace ns1
{ struct Bar
: ns0::Foo
{}; }
86 namespace A
{ void foo(ns0::Foo
*p
, int y
, int z
= 0); } // expected-note {{candidate}}
87 namespace ns1
{ using A::foo
; }
88 namespace ns2
{ struct Baz
: ns1::Bar
{}; }
89 namespace A
{ void foo(ns0::Foo
*p
, int y
= 0, int z
); }
91 void test(ns2::Baz
*p
) {
92 foo(p
, 0, 0); // okay!
93 foo(p
, 0); // should be fine!
94 foo(p
); // expected-error {{no matching function}}
99 namespace ns
{ int foo
; }
100 template <class T
> using ns::foo
; // expected-error {{cannot template a using declaration}}
104 template <typename T
> void f(T
);
107 template <typename T
> using A::f
<T
>; // expected-error {{cannot template a using declaration}}
114 class Class1
; // expected-note{{forward declaration}}
117 using ::foo::Class1::Function
; // expected-error{{incomplete type 'foo::Class1' named in nested name specifier}}
121 // Don't suggest non-typenames for positions requiring typenames.
122 namespace using_suggestion_tyname_val
{
123 namespace N
{ void FFF() {} }
124 using typename
N::FFG
; // expected-error {{no member named 'FFG' in namespace 'using_suggestion_tyname_val::N'}}
127 namespace using_suggestion_member_tyname_val
{
128 class CCC
{ public: void AAA() { } };
129 class DDD
: public CCC
{ public: using typename
CCC::AAB
; }; // expected-error {{no member named 'AAB' in 'using_suggestion_member_tyname_val::CCC'}}
132 namespace using_suggestion_tyname_val_dropped_specifier
{
135 using typename
N::FFG
; // expected-error {{no member named 'FFG' in namespace 'using_suggestion_tyname_val_dropped_specifier::N'}}
138 // Currently hints aren't provided to drop out the incorrect M::.
139 namespace using_suggestion_ty_dropped_nested_specifier
{
141 class AAA
{}; // expected-note {{'N::AAA' declared here}}
144 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 namespace using_suggestion_tyname_ty_dropped_nested_specifier
{
149 class AAA
{}; // expected-note {{'N::AAA' declared here}}
152 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 namespace using_suggestion_val_dropped_nested_specifier
{
157 void FFF() {} // expected-note {{'N::FFF' declared here}}
160 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 namespace UsingDeclVsHiddenName
{
165 enum HiddenTag1
{}; // expected-note {{previous use is here}}
166 enum HiddenTag2
{}; // expected-note {{target}}
167 int HiddenFn1
; // expected-note {{target}}
168 int HiddenFn2
; // expected-note {{target}}
169 int HiddenLocalExtern1
;
170 int HiddenLocalExtern2
;
175 using A::HiddenFn1
; // expected-note {{using declaration}}
176 using A::HiddenLocalExtern1
;
179 friend struct HiddenTag1
; // expected-error {{tag type that does not match previous}}
180 friend struct HiddenTag2
; // expected-note {{conflicting declaration}}
181 friend void HiddenFn1(); // expected-error {{cannot befriend target of using declaration}}
182 friend void HiddenFn2(); // expected-note {{conflicting declaration}}
184 // OK, these are not in the scope of namespace B, even though they're
185 // members of the namespace.
186 void HiddenLocalExtern1();
187 void HiddenLocalExtern2();
191 using A::HiddenTag2
; // expected-error {{conflicts with declaration already in scope}}
192 using A::HiddenFn2
; // expected-error {{conflicts with declaration already in scope}}
193 using A::HiddenLocalExtern2
;
208 #if __cplusplus < 201103L
209 // expected-error@-2 {{no member named 'S' in 'PR19171::S'}}
213 // [namespace.udecl]p3: In a using-declaration used as a member-declaration,
214 // the nested-name-specifier shall name a base class of the class being defined.
215 // If such a using-declaration names a constructor, the nested-name-specifier
216 // shall name a direct base class of the class being defined;
219 struct C_blah
: B_blah
{ C_blah(int); }; // expected-note 0-1{{declared here}}
221 // FIXME: We should be able to correct this in C++11 mode.
222 using B_blah::C_blah
; // expected-error-re {{no member named 'C_blah' in 'PR19171::B_blah'{{$}}}}
225 // Somewhat bizarrely, this names the injected-class-name of B_blah within
226 // C_blah, and is valid.
227 using C_blah::B_blah
;
230 using C_blah::D_blah
;
231 #if __cplusplus < 201103L
232 // expected-error-re@-2 {{no member named 'D_blah' in 'PR19171::C_blah'{{$}}}}
234 // expected-error@-4 {{no member named 'D_blah' in 'PR19171::C_blah'; did you mean 'C_blah'?}}
237 #if __cplusplus >= 201103L
242 struct EE
{ int EE
; };
244 using E::EE
; // expected-error-re {{no member named 'EE' in 'PR19171::E'{{$}}}}
247 struct TypoDuplicate
{ // expected-note 0-4{{here}}
249 void foobar(); // expected-note 2{{here}}
251 struct TypoDuplicateDerived1
: TypoDuplicate
{
252 #if __cplusplus >= 201103L
253 using TypoDuplicate::TypoFuplicate
; // expected-error {{did you mean 'TypoDuplicate'}} expected-note {{previous}}
254 using TypoDuplicate::TypoDuplicate
; // expected-error {{redeclaration}}
256 using TypoDuplicate::goobar
; // expected-error {{did you mean 'foobar'}} expected-note {{previous}}
257 using TypoDuplicate::foobar
; // expected-error {{redeclaration}}
259 struct TypoDuplicateDerived2
: TypoDuplicate
{
260 #if __cplusplus >= 201103L
261 using TypoFuplicate::TypoDuplicate
; // expected-error {{did you mean 'TypoDuplicate'}} expected-note {{previous}}
262 using TypoDuplicate::TypoDuplicate
; // expected-error {{redeclaration}}
265 struct TypoDuplicateDerived3
: TypoDuplicate
{
266 #if __cplusplus >= 201103L
267 // FIXME: Don't suggest a correction that would lead to a redeclaration
268 // error here... or at least diagnose the error.
269 using TypoDuplicate::TypoDuplicate
;
270 using TypoDuplicate::TypoFuplicate
; // expected-error {{did you mean 'TypoDuplicate'}}
272 using TypoDuplicate::foobar
;
273 using TypoDuplicate::goobar
; // expected-error {{did you mean 'foobar'}}
275 struct TypoDuplicateDerived4
: TypoDuplicate
{
276 #if __cplusplus >= 201103L
277 using TypoDuplicate::TypoDuplicate
; // expected-note {{previous}}
278 using TypoFuplicate::TypoDuplicate
; // expected-error {{did you mean 'TypoDuplicate'}} expected-error {{redeclaration}}
283 namespace TypoCorrectTemplateMember
{
285 template<typename T
> void foobar(T
); // expected-note {{'foobar' declared here}}
288 using A::goobar
; // expected-error {{no member named 'goobar' in 'TypoCorrectTemplateMember::A'; did you mean 'foobar'?}}
292 namespace use_instance_in_static
{
296 static int f() { return n
; } // expected-error {{invalid use of member 'n' in static member function}}
302 class A
; // expected-note {{target}}
303 int i
; // expected-note {{target}}
306 using X::A
; // expected-note {{using}}
307 using X::i
; // expected-note {{using}}
308 class A
{}; // expected-error {{conflicts}}
309 int i
; // expected-error {{conflicts}}
314 extern int a
; // expected-note 2{{target of using declaration}}
315 void f(); // expected-note 2{{target of using declaration}}
316 struct s
; // expected-note 2{{target of using declaration}}
317 enum e
{}; // expected-note 2{{target of using declaration}}
319 template<typename
> extern int vt
; // expected-note 2{{target of using declaration}} expected-warning 0-1{{extension}}
320 template<typename
> void ft(); // expected-note 2{{target of using declaration}}
321 template<typename
> struct st
; // expected-note 2{{target of using declaration}}
324 using PR24033::a
; // expected-note {{using declaration}}
325 using PR24033::f
; // expected-note {{using declaration}}
326 using PR24033::s
; // expected-note {{using declaration}}
327 using PR24033::e
; // expected-note {{using declaration}}
329 using PR24033::vt
; // expected-note {{using declaration}}
330 using PR24033::ft
; // expected-note {{using declaration}}
331 using PR24033::st
; // expected-note {{using declaration}}
333 extern int a
; // expected-error {{declaration conflicts with target of using declaration already in scope}}
334 void f(); // expected-error {{declaration conflicts with target of using declaration already in scope}}
335 struct s
; // expected-error {{declaration conflicts with target of using declaration already in scope}}
336 enum e
{}; // expected-error {{declaration conflicts with target of using declaration already in scope}}
338 template<typename
> extern int vt
; // expected-error {{declaration conflicts with target of using declaration already in scope}} expected-warning 0-1{{extension}}
339 template<typename
> void ft(); // expected-error {{declaration conflicts with target of using declaration already in scope}}
340 template<typename
> struct st
; // expected-error {{declaration conflicts with target of using declaration already in scope}}
344 extern int a
; // expected-note {{conflicting declaration}}
345 void f(); // expected-note {{conflicting declaration}}
346 struct s
; // expected-note {{conflicting declaration}}
347 enum e
{}; // expected-note {{conflicting declaration}}
349 template<typename
> extern int vt
; // expected-note {{conflicting declaration}} expected-warning 0-1{{extension}}
350 template<typename
> void ft(); // expected-note {{conflicting declaration}}
351 template<typename
> struct st
; // expected-note {{conflicting declaration}}
353 using PR24033::a
; // expected-error {{target of using declaration conflicts with declaration already in scope}}
354 using PR24033::f
; // expected-error {{target of using declaration conflicts with declaration already in scope}}
355 using PR24033::s
; // expected-error {{target of using declaration conflicts with declaration already in scope}}
356 using PR24033::e
; // expected-error {{target of using declaration conflicts with declaration already in scope}}
358 using PR24033::vt
; // expected-error {{target of using declaration conflicts with declaration already in scope}}
359 using PR24033::ft
; // expected-error {{target of using declaration conflicts with declaration already in scope}}
360 using PR24033::st
; // expected-error {{target of using declaration conflicts with declaration already in scope}}
364 namespace field_use
{
365 struct A
{ int field
; };
367 // Previously Clang rejected this valid C++11 code because it didn't look
368 // through the UsingShadowDecl.
370 #if __cplusplus < 201103L
371 // expected-error@+2 {{invalid use of non-static data member 'field'}}
373 enum { X
= sizeof(field
) };
377 namespace tag_vs_var
{
400 // expected-error@+5 {{requires a qualified name}}
401 // expected-error@+4 {{expected ';'}}
402 // expected-error@+3 {{expected '}'}}
403 // expected-note@+2 {{to match this '{'}}
404 // expected-error@+1 {{expected ';'}}
405 template<class> struct S
{ using S