using-decl-1.cpp revision 7edb5fdf9703e1abd780417db691b77d5fcbc610
1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s 2bc13ab2bc75bd997a2a40e371f50a4c456d8ee69Anders Carlsson 3bc13ab2bc75bd997a2a40e371f50a4c456d8ee69Anders Carlssonextern "C" { void f(bool); } 4bc13ab2bc75bd997a2a40e371f50a4c456d8ee69Anders Carlsson 5bc13ab2bc75bd997a2a40e371f50a4c456d8ee69Anders Carlssonnamespace std { 6bc13ab2bc75bd997a2a40e371f50a4c456d8ee69Anders Carlsson using ::f; 7bc13ab2bc75bd997a2a40e371f50a4c456d8ee69Anders Carlsson inline void f() { return f(true); } 8bc13ab2bc75bd997a2a40e371f50a4c456d8ee69Anders Carlsson} 92531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregor 102531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregornamespace M { 112531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregor void f(float); 122531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregor} 132531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregor 142531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregornamespace N { 152531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregor using M::f; 162531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregor void f(int) { } // expected-note{{previous}} 172531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregor 182531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregor void f(int) { } // expected-error{{redefinition}} 192531c2d2f1e8ce35f2ce8e9539738ddf8dccb7ccDouglas Gregor} 20891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor 21891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregornamespace N { 22891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor void f(double); 23891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor void f(long); 24891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor} 25891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor 26891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregorstruct X0 { 27891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor void operator()(int); 28891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor void operator()(long); 29891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor}; 30891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor 31891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregorstruct X1 : X0 { 32891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor // FIXME: give this operator() a 'float' parameter to test overloading 33891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor // behavior. It currently fails. 34891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor void operator()(); 35891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor using X0::operator(); 36891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor 37891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor void test() { 38891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor (*this)(1); 39891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor } 40891fdae811e991d15b26fc165724c4cf6b6737a6Douglas Gregor}; 41ca910e84ea026a898c7184d3f3608403005b9bc0Anders Carlsson 42ca910e84ea026a898c7184d3f3608403005b9bc0Anders Carlssonstruct A { void f(); }; 43ca910e84ea026a898c7184d3f3608403005b9bc0Anders Carlssonstruct B : A { }; 44ca910e84ea026a898c7184d3f3608403005b9bc0Anders Carlssonclass C : B { using B::f; }; 45bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth 46bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth// PR5751: Resolve overloaded functions through using decls. 47bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruthnamespace O { 48bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth void f(int i); 49bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth void f(double d); 50bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth} 51bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruthnamespace P { 52bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth void f(); 53bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth void g(void (*ptr)(int)); 54bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth using O::f; 55bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth void test() { 56bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth f(); 57bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth f(1); 58bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth void (*f_ptr1)(double) = f; 59bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth void (*f_ptr2)() = f; 60bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth g(f); 61bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth } 62bd64729ac6de8fed320e7a722597cc5444709c63Chandler Carruth} 63a113e7263c5337731c65fada9de7ff72af25423bJohn McCall 64a113e7263c5337731c65fada9de7ff72af25423bJohn McCall// Make sure that ADL can find names brought in by using decls. 65a113e7263c5337731c65fada9de7ff72af25423bJohn McCallnamespace test0 { 66a113e7263c5337731c65fada9de7ff72af25423bJohn McCall namespace ns { 67a113e7263c5337731c65fada9de7ff72af25423bJohn McCall class Foo {}; 68a113e7263c5337731c65fada9de7ff72af25423bJohn McCall 69a113e7263c5337731c65fada9de7ff72af25423bJohn McCall namespace inner { 70a113e7263c5337731c65fada9de7ff72af25423bJohn McCall void foo(char *); // expected-note {{no known conversion}} 71a113e7263c5337731c65fada9de7ff72af25423bJohn McCall } 72a113e7263c5337731c65fada9de7ff72af25423bJohn McCall 73a113e7263c5337731c65fada9de7ff72af25423bJohn McCall using inner::foo; 74a113e7263c5337731c65fada9de7ff72af25423bJohn McCall } 75a113e7263c5337731c65fada9de7ff72af25423bJohn McCall 76a113e7263c5337731c65fada9de7ff72af25423bJohn McCall void test(ns::Foo *p) { 77a113e7263c5337731c65fada9de7ff72af25423bJohn McCall foo(*p); // expected-error {{no matching function for call to 'foo'}} 78a113e7263c5337731c65fada9de7ff72af25423bJohn McCall } 79a113e7263c5337731c65fada9de7ff72af25423bJohn McCall} 807edb5fdf9703e1abd780417db691b77d5fcbc610John McCall 817edb5fdf9703e1abd780417db691b77d5fcbc610John McCall// Redeclarations! 827edb5fdf9703e1abd780417db691b77d5fcbc610John McCallnamespace test1 { 837edb5fdf9703e1abd780417db691b77d5fcbc610John McCall namespace ns0 { struct Foo {}; } 847edb5fdf9703e1abd780417db691b77d5fcbc610John McCall namespace A { void foo(ns0::Foo *p, int y, int z); } 857edb5fdf9703e1abd780417db691b77d5fcbc610John McCall namespace ns2 { using A::foo; } 867edb5fdf9703e1abd780417db691b77d5fcbc610John McCall namespace ns1 { struct Bar : ns0::Foo {}; } 877edb5fdf9703e1abd780417db691b77d5fcbc610John McCall namespace A { void foo(ns0::Foo *p, int y, int z = 0); } // expected-note {{candidate}} 887edb5fdf9703e1abd780417db691b77d5fcbc610John McCall namespace ns1 { using A::foo; } 897edb5fdf9703e1abd780417db691b77d5fcbc610John McCall namespace ns2 { struct Baz : ns1::Bar {}; } 907edb5fdf9703e1abd780417db691b77d5fcbc610John McCall namespace A { void foo(ns0::Foo *p, int y = 0, int z); } 917edb5fdf9703e1abd780417db691b77d5fcbc610John McCall 927edb5fdf9703e1abd780417db691b77d5fcbc610John McCall void test(ns2::Baz *p) { 937edb5fdf9703e1abd780417db691b77d5fcbc610John McCall foo(p, 0, 0); // okay! 947edb5fdf9703e1abd780417db691b77d5fcbc610John McCall foo(p, 0); // should be fine! 957edb5fdf9703e1abd780417db691b77d5fcbc610John McCall foo(p); // expected-error {{no matching function}} 967edb5fdf9703e1abd780417db691b77d5fcbc610John McCall } 977edb5fdf9703e1abd780417db691b77d5fcbc610John McCall} 98