Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Douglas Gregor | 953a61f | 2013-02-07 19:01:24 +0000 | [diff] [blame^] | 2 | // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 3 | |
Richard Smith | bbcd0f3 | 2013-02-07 03:37:08 +0000 | [diff] [blame] | 4 | int &global(int); |
| 5 | int &global2(int); |
Richard Smith | 1b7f9cb | 2012-03-13 03:12:56 +0000 | [diff] [blame] | 6 | |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 7 | namespace N6 { |
| 8 | char &f(char); |
| 9 | } |
| 10 | |
Douglas Gregor | 0fdc09f | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 11 | namespace N8 { } |
| 12 | |
Richard Smith | bbcd0f3 | 2013-02-07 03:37:08 +0000 | [diff] [blame] | 13 | namespace LookupBeforeImport { |
| 14 | int &f(int); |
| 15 | } |
| 16 | void testEarly() { |
| 17 | int &r = LookupBeforeImport::f(1); |
| 18 | } |
| 19 | |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 20 | @import namespaces_left; |
| 21 | @import namespaces_right; |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 22 | |
| 23 | void test() { |
| 24 | int &ir1 = N1::f(1); |
| 25 | int &ir2 = N2::f(1); |
| 26 | int &ir3 = N3::f(1); |
Richard Smith | bbcd0f3 | 2013-02-07 03:37:08 +0000 | [diff] [blame] | 27 | int &ir4 = global(1); |
| 28 | int &ir5 = ::global2(1); |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 29 | float &fr1 = N1::f(1.0f); |
| 30 | float &fr2 = N2::f(1.0f); |
Richard Smith | bbcd0f3 | 2013-02-07 03:37:08 +0000 | [diff] [blame] | 31 | float &fr3 = global(1.0f); |
| 32 | float &fr4 = ::global2(1.0f); |
| 33 | float &fr5 = LookupBeforeImport::f(1.0f); |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 34 | double &dr1 = N2::f(1.0); |
| 35 | double &dr2 = N3::f(1.0); |
Richard Smith | bbcd0f3 | 2013-02-07 03:37:08 +0000 | [diff] [blame] | 36 | double &dr3 = global(1.0); |
| 37 | double &dr4 = ::global2(1.0); |
| 38 | double &dr5 = LookupBeforeImport::f(1.0); |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 39 | } |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 40 | |
| 41 | // Test namespaces merged without a common first declaration. |
| 42 | namespace N5 { |
| 43 | char &f(char); |
| 44 | } |
| 45 | |
Douglas Gregor | 0fdc09f | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 46 | namespace N10 { |
| 47 | int &f(int); |
| 48 | } |
| 49 | |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 50 | void testMerged() { |
| 51 | int &ir1 = N5::f(17); |
| 52 | int &ir2 = N6::f(17); |
| 53 | int &ir3 = N7::f(17); |
| 54 | double &fr1 = N5::f(1.0); |
| 55 | double &fr2 = N6::f(1.0); |
| 56 | double &fr3 = N7::f(1.0); |
| 57 | char &cr1 = N5::f('a'); |
| 58 | char &cr2 = N6::f('b'); |
| 59 | } |
| 60 | |
Douglas Gregor | 0fdc09f | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 61 | // Test merging of declarations within namespaces that themselves were |
| 62 | // merged without a common first declaration. |
| 63 | void testMergedMerged() { |
| 64 | int &ir1 = N8::f(17); |
| 65 | int &ir2 = N9::f(17); |
| 66 | int &ir3 = N10::f(17); |
| 67 | } |
Douglas Gregor | 1c3875d | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 68 | |
| 69 | // Test merging when using anonymous namespaces, which does not |
| 70 | // actually perform any merging. |
Douglas Gregor | 1c3875d | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 71 | void testAnonymousNotMerged() { |
| 72 | N11::consumeFoo(N11::getFoo()); // expected-error{{cannot initialize a parameter of type 'N11::<anonymous>::Foo *' with an rvalue of type 'N11::<anonymous>::Foo *'}} |
| 73 | N12::consumeFoo(N12::getFoo()); // expected-error{{cannot initialize a parameter of type 'N12::<anonymous>::Foo *' with an rvalue of type 'N12::<anonymous>::Foo *'}} |
| 74 | } |
| 75 | |
Richard Smith | bbcd0f3 | 2013-02-07 03:37:08 +0000 | [diff] [blame] | 76 | // namespaces-right.h: expected-note@60 {{passing argument to parameter here}} |
| 77 | // namespaces-right.h: expected-note@67 {{passing argument to parameter here}} |