1f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor// RUN: rm -rf %t 2a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar// RUN: %clang_cc1 -x objective-c++ -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs %s -verify 3f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor 4bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smithint &global(int); 5bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smithint &global2(int); 61b7f9cbed1b96b58a6e5f7808ebc9345a76a0936Richard Smith 7c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregornamespace N6 { 8c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor char &f(char); 9c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor} 10c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 110fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregornamespace N8 { } 120fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor 13bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smithnamespace LookupBeforeImport { 14bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith int &f(int); 15bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith} 16bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smithvoid testEarly() { 17bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith int &r = LookupBeforeImport::f(1); 18bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith} 19bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith 201b257afbae854c6817f26b7d61c4fed8ff7aebadDouglas Gregor@import namespaces_left; 211b257afbae854c6817f26b7d61c4fed8ff7aebadDouglas Gregor@import namespaces_right; 22f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor 23f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregorvoid test() { 24f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor int &ir1 = N1::f(1); 25f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor int &ir2 = N2::f(1); 26f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor int &ir3 = N3::f(1); 27bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith int &ir4 = global(1); 28bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith int &ir5 = ::global2(1); 29f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor float &fr1 = N1::f(1.0f); 30f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor float &fr2 = N2::f(1.0f); 31bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith float &fr3 = global(1.0f); 32bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith float &fr4 = ::global2(1.0f); 33bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith float &fr5 = LookupBeforeImport::f(1.0f); 34f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor double &dr1 = N2::f(1.0); 35f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor double &dr2 = N3::f(1.0); 36bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith double &dr3 = global(1.0); 37bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith double &dr4 = ::global2(1.0); 38bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith double &dr5 = LookupBeforeImport::f(1.0); 39651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 40651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines struct AddAndReexportBeforeImport::S s; 41651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines int k = AddAndReexportBeforeImport::S; 42f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor} 43c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 44c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor// Test namespaces merged without a common first declaration. 45c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregornamespace N5 { 46c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor char &f(char); 47c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor} 48c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 490fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregornamespace N10 { 500fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor int &f(int); 510fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor} 520fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor 53c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregorvoid testMerged() { 54c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor int &ir1 = N5::f(17); 55c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor int &ir2 = N6::f(17); 56c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor int &ir3 = N7::f(17); 57c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor double &fr1 = N5::f(1.0); 58c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor double &fr2 = N6::f(1.0); 59c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor double &fr3 = N7::f(1.0); 60c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor char &cr1 = N5::f('a'); 61c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor char &cr2 = N6::f('b'); 62c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor} 63c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 640fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor// Test merging of declarations within namespaces that themselves were 650fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor// merged without a common first declaration. 660fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregorvoid testMergedMerged() { 670fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor int &ir1 = N8::f(17); 680fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor int &ir2 = N9::f(17); 690fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor int &ir3 = N10::f(17); 700fdc09fe680787b855cf20183c4bd3b83f2c907fDouglas Gregor} 711c3875dab92f3b0a25212c80863e452cb269d3f1Douglas Gregor 721c3875dab92f3b0a25212c80863e452cb269d3f1Douglas Gregor// Test merging when using anonymous namespaces, which does not 731c3875dab92f3b0a25212c80863e452cb269d3f1Douglas Gregor// actually perform any merging. 741c3875dab92f3b0a25212c80863e452cb269d3f1Douglas Gregorvoid testAnonymousNotMerged() { 75651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines N11::consumeFoo(N11::getFoo()); // expected-error{{cannot initialize a parameter of type 'N11::(anonymous namespace)::Foo *' with an rvalue of type 'N11::(anonymous namespace)::Foo *'}} 76651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines N12::consumeFoo(N12::getFoo()); // expected-error{{cannot initialize a parameter of type 'N12::(anonymous namespace)::Foo *' with an rvalue of type 'N12::(anonymous namespace)::Foo *'}} 771c3875dab92f3b0a25212c80863e452cb269d3f1Douglas Gregor} 781c3875dab92f3b0a25212c80863e452cb269d3f1Douglas Gregor 79b42f200777a66b98989160bf3987ce431540a584Andy Gibbs// expected-note@Inputs/namespaces-right.h:60 {{passing argument to parameter here}} 80b42f200777a66b98989160bf3987ce431540a584Andy Gibbs// expected-note@Inputs/namespaces-right.h:67 {{passing argument to parameter here}} 81b7165589b2eafc4b48d09a5914e21604ae580256Richard Smith 82b7165589b2eafc4b48d09a5914e21604ae580256Richard Smith// Test that bringing in one name from an overload set does not hide the rest. 83b7165589b2eafc4b48d09a5914e21604ae580256Richard Smithvoid testPartialImportOfOverloadSet() { 84b7165589b2eafc4b48d09a5914e21604ae580256Richard Smith void (*p)() = N13::p; 85b7165589b2eafc4b48d09a5914e21604ae580256Richard Smith p(); 86b7165589b2eafc4b48d09a5914e21604ae580256Richard Smith N13::f(0); 87b7165589b2eafc4b48d09a5914e21604ae580256Richard Smith} 88