1 // RUN: rm -rf %t 2 // RUN: mkdir -p %t 3 // RUN: %clang_cc1 -std=c++2a -x c++-header %S/Inputs/header.h -emit-header-module -fmodule-name=FIXME -o %t/h.pcm 4 // RUN: %clang_cc1 -std=c++2a %s -DX_INTERFACE -emit-module-interface -o %t/x.pcm 5 // RUN: %clang_cc1 -std=c++2a %s -DY_INTERFACE -emit-module-interface -o %t/y.pcm 6 // RUN: %clang_cc1 -std=c++2a %s -DINTERFACE -fmodule-file=%t/x.pcm -fmodule-file=%t/y.pcm -emit-module-interface -o %t/m.pcm 7 // RUN: %clang_cc1 -std=c++2a %s -DIMPLEMENTATION -I%S/Inputs -fmodule-file=%t/h.pcm -fmodule-file=%t/m.pcm -verify 8 // RUN: %clang_cc1 -std=c++2a %s -DUSER -I%S/Inputs -fmodule-file=%t/h.pcm -fmodule-file=%t/m.pcm -verify 9 10 #if defined(X_INTERFACE) 11 export module X; 12 export int x; 13 14 #elif defined(Y_INTERFACE) 15 export module Y; 16 export int y; 17 18 #elif defined(INTERFACE) 19 export module p2; 20 export import X; 21 import Y; // not exported 22 23 namespace A { 24 int f(); 25 export int g(); 26 int h(); 27 namespace inner {} 28 } 29 export namespace B { 30 namespace inner {} 31 } 32 namespace B { 33 int f(); 34 } 35 namespace C {} 36 namespace D { int f(); } 37 export namespace D {} 38 39 #elif defined(IMPLEMENTATION) 40 module p2; 41 import "header.h"; 42 43 // Per [basic.scope.namespace]/2.3, exportedness has no impact on visibility 44 // within the same module. 45 // 46 // expected-no-diagnostics 47 48 void use() { 49 A::f(); 50 A::g(); 51 A::h(); 52 using namespace A::inner; 53 54 using namespace B; 55 using namespace B::inner; 56 B::f(); 57 f(); 58 59 using namespace C; 60 61 D::f(); 62 } 63 64 int use_header() { return foo + bar::baz(); } 65 66 #elif defined(USER) 67 import p2; 68 import "header.h"; 69 70 void use() { 71 // namespace A is implicitly exported by the export of A::g. 72 A::f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}} 73 // expected-note@* {{declaration here is not visible}} 74 A::g(); 75 A::h(); // expected-error {{declaration of 'h' must be imported from module 'p2' before it is required}} 76 // expected-note@* {{declaration here is not visible}} 77 using namespace A::inner; // expected-error {{declaration of 'inner' must be imported from module 'p2' before it is required}} 78 // expected-note@* {{declaration here is not visible}} 79 80 // namespace B and B::inner are explicitly exported 81 using namespace B; 82 using namespace B::inner; 83 B::f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}} 84 // expected-note@* {{declaration here is not visible}} 85 f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}} 86 // expected-note@* {{declaration here is not visible}} 87 88 // namespace C is not exported 89 using namespace C; // expected-error {{declaration of 'C' must be imported from module 'p2' before it is required}} 90 // expected-note@* {{declaration here is not visible}} 91 92 // namespace D is exported, but D::f is not 93 D::f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}} 94 // expected-note@* {{declaration here is not visible}} 95 } 96 97 int use_header() { return foo + bar::baz(); } 98 99 #else 100 #error unknown mode 101 #endif 102