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; 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; 17 void f(int) { } // expected-note{{previous}} 18 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 38 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; 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 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 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 { 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 { 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 { 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 { 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}} 185 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; 263 static int f() { return n; } // expected-error {{invalid use of member 'n' in static member function}} 264 }; 265 } 266 267 namespace PR24030 { 268 namespace X { 269 class A; // expected-note {{target}} 270 int i; // expected-note {{target}} 271 } 272 namespace Y { 273 using X::A; // expected-note {{using}} 274 using X::i; // expected-note {{using}} 275 class A {}; // expected-error {{conflicts}} 276 int i; // expected-error {{conflicts}} 277 } 278 } 279 280 namespace PR24033 { 281 extern int a; // expected-note 2{{target of using declaration}} 282 void f(); // expected-note 2{{target of using declaration}} 283 struct s; // expected-note 2{{target of using declaration}} 284 enum e {}; // expected-note 2{{target of using declaration}} 285 286 template<typename> extern int vt; // expected-note 2{{target of using declaration}} expected-warning 0-1{{extension}} 287 template<typename> void ft(); // expected-note 2{{target of using declaration}} 288 template<typename> struct st; // expected-note 2{{target of using declaration}} 289 290 namespace X { 291 using PR24033::a; // expected-note {{using declaration}} 292 using PR24033::f; // expected-note {{using declaration}} 293 using PR24033::s; // expected-note {{using declaration}} 294 using PR24033::e; // expected-note {{using declaration}} 295 296 using PR24033::vt; // expected-note {{using declaration}} 297 using PR24033::ft; // expected-note {{using declaration}} 298 using PR24033::st; // expected-note {{using declaration}} 299 300 extern int a; // expected-error {{declaration conflicts with target of using declaration already in scope}} 301 void f(); // expected-error {{declaration conflicts with target of using declaration already in scope}} 302 struct s; // expected-error {{declaration conflicts with target of using declaration already in scope}} 303 enum e {}; // expected-error {{declaration conflicts with target of using declaration already in scope}} 304 305 template<typename> extern int vt; // expected-error {{declaration conflicts with target of using declaration already in scope}} expected-warning 0-1{{extension}} 306 template<typename> void ft(); // expected-error {{declaration conflicts with target of using declaration already in scope}} 307 template<typename> struct st; // expected-error {{declaration conflicts with target of using declaration already in scope}} 308 } 309 310 namespace Y { 311 extern int a; // expected-note {{conflicting declaration}} 312 void f(); // expected-note {{conflicting declaration}} 313 struct s; // expected-note {{conflicting declaration}} 314 enum e {}; // expected-note {{conflicting declaration}} 315 316 template<typename> extern int vt; // expected-note {{conflicting declaration}} expected-warning 0-1{{extension}} 317 template<typename> void ft(); // expected-note {{conflicting declaration}} 318 template<typename> struct st; // expected-note {{conflicting declaration}} 319 320 using PR24033::a; // expected-error {{target of using declaration conflicts with declaration already in scope}} 321 using PR24033::f; // expected-error {{target of using declaration conflicts with declaration already in scope}} 322 using PR24033::s; // expected-error {{target of using declaration conflicts with declaration already in scope}} 323 using PR24033::e; // expected-error {{target of using declaration conflicts with declaration already in scope}} 324 325 using PR24033::vt; // expected-error {{target of using declaration conflicts with declaration already in scope}} 326 using PR24033::ft; // expected-error {{target of using declaration conflicts with declaration already in scope}} 327 using PR24033::st; // expected-error {{target of using declaration conflicts with declaration already in scope}} 328 } 329 } 330 331 namespace field_use { 332 struct A { int field; }; 333 struct B : A { 334 // Previously Clang rejected this valid C++11 code because it didn't look 335 // through the UsingShadowDecl. 336 using A::field; 337 #if __cplusplus < 201103L 338 // expected-error@+2 {{invalid use of non-static data member 'field'}} 339 #endif 340 enum { X = sizeof(field) }; 341 }; 342 } 343