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