blob: a6f4c25cc0944e78f071d27eaa51705a5c714914 [file] [log] [blame]
Douglas Gregorf5c9f9f2012-01-07 09:11:48 +00001// RUN: rm -rf %t
Douglas Gregor953a61f2013-02-07 19:01:24 +00002// RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify
Douglas Gregorf5c9f9f2012-01-07 09:11:48 +00003
Richard Smithbbcd0f32013-02-07 03:37:08 +00004int &global(int);
5int &global2(int);
Richard Smith1b7f9cb2012-03-13 03:12:56 +00006
Douglas Gregorc6c8e0e2012-01-09 17:30:44 +00007namespace N6 {
8 char &f(char);
9}
10
Douglas Gregor0fdc09f2012-01-09 17:38:47 +000011namespace N8 { }
12
Richard Smithbbcd0f32013-02-07 03:37:08 +000013namespace LookupBeforeImport {
14 int &f(int);
15}
16void testEarly() {
17 int &r = LookupBeforeImport::f(1);
18}
19
Douglas Gregor1b257af2012-12-11 22:11:52 +000020@import namespaces_left;
21@import namespaces_right;
Douglas Gregorf5c9f9f2012-01-07 09:11:48 +000022
23void test() {
24 int &ir1 = N1::f(1);
25 int &ir2 = N2::f(1);
26 int &ir3 = N3::f(1);
Richard Smithbbcd0f32013-02-07 03:37:08 +000027 int &ir4 = global(1);
28 int &ir5 = ::global2(1);
Douglas Gregorf5c9f9f2012-01-07 09:11:48 +000029 float &fr1 = N1::f(1.0f);
30 float &fr2 = N2::f(1.0f);
Richard Smithbbcd0f32013-02-07 03:37:08 +000031 float &fr3 = global(1.0f);
32 float &fr4 = ::global2(1.0f);
33 float &fr5 = LookupBeforeImport::f(1.0f);
Douglas Gregorf5c9f9f2012-01-07 09:11:48 +000034 double &dr1 = N2::f(1.0);
35 double &dr2 = N3::f(1.0);
Richard Smithbbcd0f32013-02-07 03:37:08 +000036 double &dr3 = global(1.0);
37 double &dr4 = ::global2(1.0);
38 double &dr5 = LookupBeforeImport::f(1.0);
Stephen Hines651f13c2014-04-23 16:59:28 -070039
40 struct AddAndReexportBeforeImport::S s;
41 int k = AddAndReexportBeforeImport::S;
Douglas Gregorf5c9f9f2012-01-07 09:11:48 +000042}
Douglas Gregorc6c8e0e2012-01-09 17:30:44 +000043
44// Test namespaces merged without a common first declaration.
45namespace N5 {
46 char &f(char);
47}
48
Douglas Gregor0fdc09f2012-01-09 17:38:47 +000049namespace N10 {
50 int &f(int);
51}
52
Douglas Gregorc6c8e0e2012-01-09 17:30:44 +000053void testMerged() {
54 int &ir1 = N5::f(17);
55 int &ir2 = N6::f(17);
56 int &ir3 = N7::f(17);
57 double &fr1 = N5::f(1.0);
58 double &fr2 = N6::f(1.0);
59 double &fr3 = N7::f(1.0);
60 char &cr1 = N5::f('a');
61 char &cr2 = N6::f('b');
62}
63
Douglas Gregor0fdc09f2012-01-09 17:38:47 +000064// Test merging of declarations within namespaces that themselves were
65// merged without a common first declaration.
66void testMergedMerged() {
67 int &ir1 = N8::f(17);
68 int &ir2 = N9::f(17);
69 int &ir3 = N10::f(17);
70}
Douglas Gregor1c3875d2012-01-09 18:07:24 +000071
72// Test merging when using anonymous namespaces, which does not
73// actually perform any merging.
Douglas Gregor1c3875d2012-01-09 18:07:24 +000074void testAnonymousNotMerged() {
Stephen Hines651f13c2014-04-23 16:59:28 -070075 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 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 *'}}
Douglas Gregor1c3875d2012-01-09 18:07:24 +000077}
78
Andy Gibbsb42f2002013-04-17 08:06:46 +000079// expected-note@Inputs/namespaces-right.h:60 {{passing argument to parameter here}}
80// expected-note@Inputs/namespaces-right.h:67 {{passing argument to parameter here}}
Richard Smithb7165582013-09-09 07:34:56 +000081
82// Test that bringing in one name from an overload set does not hide the rest.
83void testPartialImportOfOverloadSet() {
84 void (*p)() = N13::p;
85 p();
86 N13::f(0);
87}