1f4a2713aSLionel Sambuc // RUN: rm -rf %t 2f4a2713aSLionel Sambuc // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify 3f4a2713aSLionel Sambuc 4f4a2713aSLionel Sambuc int &global(int); 5f4a2713aSLionel Sambuc int &global2(int); 6f4a2713aSLionel Sambuc 7f4a2713aSLionel Sambuc namespace N6 { 8f4a2713aSLionel Sambuc char &f(char); 9f4a2713aSLionel Sambuc } 10f4a2713aSLionel Sambuc 11f4a2713aSLionel Sambuc namespace N8 { } 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc namespace LookupBeforeImport { 14f4a2713aSLionel Sambuc int &f(int); 15f4a2713aSLionel Sambuc } testEarly()16f4a2713aSLionel Sambucvoid testEarly() { 17f4a2713aSLionel Sambuc int &r = LookupBeforeImport::f(1); 18f4a2713aSLionel Sambuc } 19f4a2713aSLionel Sambuc 20f4a2713aSLionel Sambuc @import namespaces_left; 21f4a2713aSLionel Sambuc @import namespaces_right; 22f4a2713aSLionel Sambuc test()23f4a2713aSLionel Sambucvoid test() { 24f4a2713aSLionel Sambuc int &ir1 = N1::f(1); 25f4a2713aSLionel Sambuc int &ir2 = N2::f(1); 26f4a2713aSLionel Sambuc int &ir3 = N3::f(1); 27f4a2713aSLionel Sambuc int &ir4 = global(1); 28f4a2713aSLionel Sambuc int &ir5 = ::global2(1); 29f4a2713aSLionel Sambuc float &fr1 = N1::f(1.0f); 30f4a2713aSLionel Sambuc float &fr2 = N2::f(1.0f); 31f4a2713aSLionel Sambuc float &fr3 = global(1.0f); 32f4a2713aSLionel Sambuc float &fr4 = ::global2(1.0f); 33f4a2713aSLionel Sambuc float &fr5 = LookupBeforeImport::f(1.0f); 34f4a2713aSLionel Sambuc double &dr1 = N2::f(1.0); 35f4a2713aSLionel Sambuc double &dr2 = N3::f(1.0); 36f4a2713aSLionel Sambuc double &dr3 = global(1.0); 37f4a2713aSLionel Sambuc double &dr4 = ::global2(1.0); 38f4a2713aSLionel Sambuc double &dr5 = LookupBeforeImport::f(1.0); 39*0a6a1f1dSLionel Sambuc 40*0a6a1f1dSLionel Sambuc struct AddAndReexportBeforeImport::S s; 41*0a6a1f1dSLionel Sambuc int k = AddAndReexportBeforeImport::S; 42f4a2713aSLionel Sambuc } 43f4a2713aSLionel Sambuc 44f4a2713aSLionel Sambuc // Test namespaces merged without a common first declaration. 45f4a2713aSLionel Sambuc namespace N5 { 46f4a2713aSLionel Sambuc char &f(char); 47f4a2713aSLionel Sambuc } 48f4a2713aSLionel Sambuc 49f4a2713aSLionel Sambuc namespace N10 { 50f4a2713aSLionel Sambuc int &f(int); 51f4a2713aSLionel Sambuc } 52f4a2713aSLionel Sambuc testMerged()53f4a2713aSLionel Sambucvoid testMerged() { 54f4a2713aSLionel Sambuc int &ir1 = N5::f(17); 55f4a2713aSLionel Sambuc int &ir2 = N6::f(17); 56f4a2713aSLionel Sambuc int &ir3 = N7::f(17); 57f4a2713aSLionel Sambuc double &fr1 = N5::f(1.0); 58f4a2713aSLionel Sambuc double &fr2 = N6::f(1.0); 59f4a2713aSLionel Sambuc double &fr3 = N7::f(1.0); 60f4a2713aSLionel Sambuc char &cr1 = N5::f('a'); 61f4a2713aSLionel Sambuc char &cr2 = N6::f('b'); 62f4a2713aSLionel Sambuc } 63f4a2713aSLionel Sambuc 64f4a2713aSLionel Sambuc // Test merging of declarations within namespaces that themselves were 65f4a2713aSLionel Sambuc // merged without a common first declaration. testMergedMerged()66f4a2713aSLionel Sambucvoid testMergedMerged() { 67f4a2713aSLionel Sambuc int &ir1 = N8::f(17); 68f4a2713aSLionel Sambuc int &ir2 = N9::f(17); 69f4a2713aSLionel Sambuc int &ir3 = N10::f(17); 70f4a2713aSLionel Sambuc } 71f4a2713aSLionel Sambuc 72f4a2713aSLionel Sambuc // Test merging when using anonymous namespaces, which does not 73f4a2713aSLionel Sambuc // actually perform any merging. testAnonymousNotMerged()74f4a2713aSLionel Sambucvoid testAnonymousNotMerged() { 75*0a6a1f1dSLionel Sambuc 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 *'}} 76*0a6a1f1dSLionel Sambuc 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 *'}} 77f4a2713aSLionel Sambuc } 78f4a2713aSLionel Sambuc 79f4a2713aSLionel Sambuc // expected-note@Inputs/namespaces-right.h:60 {{passing argument to parameter here}} 80f4a2713aSLionel Sambuc // expected-note@Inputs/namespaces-right.h:67 {{passing argument to parameter here}} 81f4a2713aSLionel Sambuc 82f4a2713aSLionel Sambuc // Test that bringing in one name from an overload set does not hide the rest. testPartialImportOfOverloadSet()83f4a2713aSLionel Sambucvoid testPartialImportOfOverloadSet() { 84f4a2713aSLionel Sambuc void (*p)() = N13::p; 85f4a2713aSLionel Sambuc p(); 86f4a2713aSLionel Sambuc N13::f(0); 87f4a2713aSLionel Sambuc } 88