| 1 |
// RUN: rm -rf %t |
| 2 |
// RUN: mkdir -p %t |
| 3 |
// RUN: split-file %s %t |
| 4 |
// |
| 5 |
// RUN: %clang_cc1 -std=c++20 -x c++-header %S/Inputs/header.h -emit-header-unit -o %t/h.pcm |
| 6 |
// RUN: %clang_cc1 -std=c++20 %t/x.cppm -emit-module-interface -o %t/x.pcm |
| 7 |
// RUN: %clang_cc1 -std=c++20 %t/y.cppm -emit-module-interface -o %t/y.pcm |
| 8 |
// 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.pcm |
| 9 |
// 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-units |
| 12 |
// 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 -verify |
| 14 |
|
| 15 |
//--- x.cppm |
| 16 |
export module X; |
| 17 |
export int x; |
| 18 |
|
| 19 |
//--- y.cppm |
| 20 |
export module Y; |
| 21 |
export int y; |
| 22 |
|
| 23 |
//--- interface.cppm |
| 24 |
export module p2; |
| 25 |
export import X; |
| 26 |
import Y; // not exported |
| 27 |
|
| 28 |
namespace A { |
| 29 |
int f(); |
| 30 |
export int g(); |
| 31 |
int h(); |
| 32 |
namespace inner {} |
| 33 |
} |
| 34 |
export namespace B { |
| 35 |
namespace inner {} |
| 36 |
} |
| 37 |
namespace B { |
| 38 |
int f(); |
| 39 |
} |
| 40 |
namespace C {} |
| 41 |
namespace D { int f(); } |
| 42 |
export namespace D {} |
| 43 |
|
| 44 |
//--- impl.cppm |
| 45 |
module p2; |
| 46 |
import "header.h"; |
| 47 |
|
| 48 |
// Per [basic.scope.namespace]/2.3, exportedness has no impact on visibility |
| 49 |
// within the same module. |
| 50 |
// |
| 51 |
// expected-no-diagnostics |
| 52 |
|
| 53 |
void 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 |
|
| 69 |
int use_header() { return foo + bar::baz(); } |
| 70 |
|
| 71 |
//--- user.cppm |
| 72 |
import p2; |
| 73 |
import "header.h"; |
| 74 |
|
| 75 |
void 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 exported |
| 85 |
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 exported |
| 93 |
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 not |
| 96 |
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 |
|
| 100 |
int use_header() { return foo + bar::baz(); } |