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