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 void operator()(float&); 34 using X0::operator(); 35 36 void test() { 37 (*this)(1); 38 } 39 }; 40 41 struct A { void f(); }; 42 struct B : A { }; 43 class C : B { using B::f; }; 44 45 // PR5751: Resolve overloaded functions through using decls. 46 namespace O { 47 void f(int i); 48 void f(double d); 49 } 50 namespace P { 51 void f(); 52 void g(void (*ptr)(int)); 53 using O::f; 54 void test() { 55 f(); 56 f(1); 57 void (*f_ptr1)(double) = f; 58 void (*f_ptr2)() = f; 59 g(f); 60 } 61 } 62 63 // Make sure that ADL can find names brought in by using decls. 64 namespace test0 { 65 namespace ns { 66 class Foo {}; 67 68 namespace inner { 69 void foo(char *); // expected-note {{no known conversion}} 70 } 71 72 using inner::foo; 73 } 74 75 void test(ns::Foo *p) { 76 foo(*p); // expected-error {{no matching function for call to 'foo'}} 77 } 78 } 79 80 // Redeclarations! 81 namespace test1 { 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); } 90 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}} 95 } 96 } 97 98 namespace test2 { 99 namespace ns { int foo; } 100 template <class T> using ns::foo; // expected-error {{cannot template a using declaration}} 101 102 // PR8022 103 struct A { 104 template <typename T> void f(T); 105 }; 106 class B : A { 107 template <typename T> using A::f<T>; // expected-error {{cannot template a using declaration}} 108 }; 109 } 110 111 // PR8756 112 namespace foo 113 { 114 class Class1; // expected-note{{forward declaration}} 115 class Class2 116 { 117 using ::foo::Class1::Function; // expected-error{{incomplete type 'foo::Class1' named in nested name specifier}} 118 }; 119 } 120 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'}} 125 } 126 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'}} 130 } 131 132 namespace using_suggestion_tyname_val_dropped_specifier { 133 void FFF() {} 134 namespace N { } 135 using typename N::FFG; // expected-error {{no member named 'FFG' in namespace 'using_suggestion_tyname_val_dropped_specifier::N'}} 136 } 137 138 // Currently hints aren't provided to drop out the incorrect M::. 139 namespace using_suggestion_ty_dropped_nested_specifier { 140 namespace N { 141 class AAA {}; // expected-note {{'N::AAA' declared here}} 142 namespace M { } 143 } 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'?}} 145 } 146 147 namespace using_suggestion_tyname_ty_dropped_nested_specifier { 148 namespace N { 149 class AAA {}; // expected-note {{'N::AAA' declared here}} 150 namespace M { } 151 } 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'?}} 153 } 154 155 namespace using_suggestion_val_dropped_nested_specifier { 156 namespace N { 157 void FFF() {} // expected-note {{'N::FFF' declared here}} 158 namespace M { } 159 } 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'?}} 161 } 162 163 namespace UsingDeclVsHiddenName { 164 namespace A { 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; 171 } 172 173 namespace B { 174 using A::HiddenTag1; 175 using A::HiddenFn1; // expected-note {{using declaration}} 176 using A::HiddenLocalExtern1; 177 178 struct S { 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}} 183 void f() { 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(); 188 } 189 }; 190 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; 194 } 195 } 196 197 namespace PR19171 { 198 struct Z { 199 Z(); 200 }; 201 202 typedef struct { 203 Z i; 204 } S; 205 206 struct Y : S { 207 using S::S; 208 #if __cplusplus < 201103L 209 // expected-error@-2 {{no member named 'S' in 'PR19171::S'}} 210 #endif 211 }; 212 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; 217 218 struct B_blah { }; 219 struct C_blah : B_blah { C_blah(int); }; // expected-note 0-1{{declared here}} 220 struct D1 : C_blah { 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'{{$}}}} 223 }; 224 struct D2 : C_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; 228 }; 229 struct D3 : C_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'{{$}}}} 233 #else 234 // expected-error@-4 {{no member named 'D_blah' in 'PR19171::C_blah'; did you mean 'C_blah'?}} 235 #endif 236 }; 237 #if __cplusplus >= 201103L 238 D3 d3(0); // ok 239 #endif 240 241 struct E { }; 242 struct EE { int EE; }; 243 struct F : E { 244 using E::EE; // expected-error-re {{no member named 'EE' in 'PR19171::E'{{$}}}} 245 }; 246 } 247 248 namespace TypoCorrectTemplateMember { 249 struct A { 250 template<typename T> void foobar(T); // expected-note {{'foobar' declared here}} 251 }; 252 struct B : A { 253 using A::goobar; // expected-error {{no member named 'goobar' in 'TypoCorrectTemplateMember::A'; did you mean 'foobar'?}} 254 }; 255 } 256 257 namespace use_instance_in_static { 258 struct A { int n; }; 259 struct B : A { 260 using A::n; 261 static int f() { return n; } // expected-error {{invalid use of member 'n' in static member function}} 262 }; 263 } 264 265 namespace PR24030 { 266 namespace X { 267 class A; // expected-note {{target}} 268 int i; // expected-note {{target}} 269 } 270 namespace Y { 271 using X::A; // expected-note {{using}} 272 using X::i; // expected-note {{using}} 273 class A {}; // expected-error {{conflicts}} 274 int i; // expected-error {{conflicts}} 275 } 276 } 277 278 namespace PR24033 { 279 extern int a; // expected-note 2{{target of using declaration}} 280 void f(); // expected-note 2{{target of using declaration}} 281 struct s; // expected-note 2{{target of using declaration}} 282 enum e {}; // expected-note 2{{target of using declaration}} 283 284 template<typename> extern int vt; // expected-note 2{{target of using declaration}} expected-warning 0-1{{extension}} 285 template<typename> void ft(); // expected-note 2{{target of using declaration}} 286 template<typename> struct st; // expected-note 2{{target of using declaration}} 287 288 namespace X { 289 using PR24033::a; // expected-note {{using declaration}} 290 using PR24033::f; // expected-note {{using declaration}} 291 using PR24033::s; // expected-note {{using declaration}} 292 using PR24033::e; // expected-note {{using declaration}} 293 294 using PR24033::vt; // expected-note {{using declaration}} 295 using PR24033::ft; // expected-note {{using declaration}} 296 using PR24033::st; // expected-note {{using declaration}} 297 298 extern int a; // expected-error {{declaration conflicts with target of using declaration already in scope}} 299 void f(); // expected-error {{declaration conflicts with target of using declaration already in scope}} 300 struct s; // expected-error {{declaration conflicts with target of using declaration already in scope}} 301 enum e {}; // expected-error {{declaration conflicts with target of using declaration already in scope}} 302 303 template<typename> extern int vt; // expected-error {{declaration conflicts with target of using declaration already in scope}} expected-warning 0-1{{extension}} 304 template<typename> void ft(); // expected-error {{declaration conflicts with target of using declaration already in scope}} 305 template<typename> struct st; // expected-error {{declaration conflicts with target of using declaration already in scope}} 306 } 307 308 namespace Y { 309 extern int a; // expected-note {{conflicting declaration}} 310 void f(); // expected-note {{conflicting declaration}} 311 struct s; // expected-note {{conflicting declaration}} 312 enum e {}; // expected-note {{conflicting declaration}} 313 314 template<typename> extern int vt; // expected-note {{conflicting declaration}} expected-warning 0-1{{extension}} 315 template<typename> void ft(); // expected-note {{conflicting declaration}} 316 template<typename> struct st; // expected-note {{conflicting declaration}} 317 318 using PR24033::a; // expected-error {{target of using declaration conflicts with declaration already in scope}} 319 using PR24033::f; // expected-error {{target of using declaration conflicts with declaration already in scope}} 320 using PR24033::s; // expected-error {{target of using declaration conflicts with declaration already in scope}} 321 using PR24033::e; // expected-error {{target of using declaration conflicts with declaration already in scope}} 322 323 using PR24033::vt; // expected-error {{target of using declaration conflicts with declaration already in scope}} 324 using PR24033::ft; // expected-error {{target of using declaration conflicts with declaration already in scope}} 325 using PR24033::st; // expected-error {{target of using declaration conflicts with declaration already in scope}} 326 } 327 } 328 329 namespace field_use { 330 struct A { int field; }; 331 struct B : A { 332 // Previously Clang rejected this valid C++11 code because it didn't look 333 // through the UsingShadowDecl. 334 using A::field; 335 #if __cplusplus < 201103L 336 // expected-error@+2 {{invalid use of non-static data member 'field'}} 337 #endif 338 enum { X = sizeof(field) }; 339 }; 340 } 341