101 lines · cpp
1// RUN: rm -rf %t2// RUN: mkdir -p %t3// RUN: split-file %s %t4//5// RUN: %clang_cc1 -std=c++20 -x c++-header %S/Inputs/header.h -emit-header-unit -o %t/h.pcm6// RUN: %clang_cc1 -std=c++20 %t/x.cppm -emit-module-interface -o %t/x.pcm7// RUN: %clang_cc1 -std=c++20 %t/y.cppm -emit-module-interface -o %t/y.pcm8// RUN: %clang_cc1 -std=c++20 %t/interface.cppm -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -emit-module-interface -o %t/m.pcm9// RUN: %clang_cc1 -std=c++20 %t/impl.cppm -I%S/Inputs -fmodule-file=%t/h.pcm \10// RUN: -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -fmodule-file=p2=%t/m.pcm -verify \11// RUN: -Wno-experimental-header-units12// RUN: %clang_cc1 -std=c++20 %t/user.cppm -I%S/Inputs -fmodule-file=%t/h.pcm -fmodule-file=p2=%t/m.pcm \13// RUN: -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -Wno-experimental-header-units -verify14 15//--- x.cppm16export module X;17export int x;18 19//--- y.cppm20export module Y;21export int y;22 23//--- interface.cppm24export module p2;25export import X;26import Y; // not exported27 28namespace A {29 int f();30 export int g();31 int h();32 namespace inner {}33}34export namespace B {35 namespace inner {}36}37namespace B {38 int f();39}40namespace C {}41namespace D { int f(); }42export namespace D {}43 44//--- impl.cppm45module p2;46import "header.h";47 48// Per [basic.scope.namespace]/2.3, exportedness has no impact on visibility49// within the same module.50//51// expected-no-diagnostics52 53void use() {54 A::f();55 A::g();56 A::h();57 using namespace A::inner;58 59 using namespace B;60 using namespace B::inner;61 B::f();62 f();63 64 using namespace C;65 66 D::f();67}68 69int use_header() { return foo + bar::baz(); }70 71//--- user.cppm72import p2;73import "header.h";74 75void use() {76 // namespace A is implicitly exported by the export of A::g.77 A::f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}}78 // expected-note@* {{declaration here is not visible}}79 A::g();80 A::h(); // expected-error {{declaration of 'h' must be imported from module 'p2' before it is required}}81 // expected-note@* {{declaration here is not visible}}82 using namespace A::inner; // expected-error {{declaration of 'inner' must be imported from module 'p2' before it is required}}83 84 // namespace B and B::inner are explicitly exported85 using namespace B;86 using namespace B::inner;87 B::f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}}88 // expected-note@* {{declaration here is not visible}}89 f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}}90 // expected-note@* {{declaration here is not visible}}91 92 // namespace C is not exported93 using namespace C; // expected-error {{declaration of 'C' must be imported from module 'p2' before it is required}}94 95 // namespace D is exported, but D::f is not96 D::f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}}97 // expected-note@* {{declaration here is not visible}}98}99 100int use_header() { return foo + bar::baz(); }101