Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / module / module.interface / p2.cpp
blobbf4e3f9650fd4ab7aaa66cc209de5d287f3f38bf
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: %clang_cc1 -std=c++20 -x c++-header %S/Inputs/header.h -emit-header-unit -o %t/h.pcm
4 // RUN: %clang_cc1 -std=c++20 %s -DX_INTERFACE -emit-module-interface -o %t/x.pcm
5 // RUN: %clang_cc1 -std=c++20 %s -DY_INTERFACE -emit-module-interface -o %t/y.pcm
6 // RUN: %clang_cc1 -std=c++20 %s -DINTERFACE -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -emit-module-interface -o %t/m.pcm
7 // RUN: %clang_cc1 -std=c++20 %s -DIMPLEMENTATION -I%S/Inputs -fmodule-file=%t/h.pcm \
8 // RUN: -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -fmodule-file=p2=%t/m.pcm -verify \
9 // RUN: -Wno-experimental-header-units
10 // RUN: %clang_cc1 -std=c++20 %s -DUSER -I%S/Inputs -fmodule-file=%t/h.pcm -fmodule-file=p2=%t/m.pcm \
11 // RUN: -fmodule-file=X=%t/x.pcm -fmodule-file=Y=%t/y.pcm -Wno-experimental-header-units -verify
13 #if defined(X_INTERFACE)
14 export module X;
15 export int x;
17 #elif defined(Y_INTERFACE)
18 export module Y;
19 export int y;
21 #elif defined(INTERFACE)
22 export module p2;
23 export import X;
24 import Y; // not exported
26 namespace A {
27 int f();
28 export int g();
29 int h();
30 namespace inner {}
32 export namespace B {
33 namespace inner {}
35 namespace B {
36 int f();
38 namespace C {}
39 namespace D { int f(); }
40 export namespace D {}
42 #elif defined(IMPLEMENTATION)
43 module p2;
44 import "header.h";
46 // Per [basic.scope.namespace]/2.3, exportedness has no impact on visibility
47 // within the same module.
49 // expected-no-diagnostics
51 void use() {
52 A::f();
53 A::g();
54 A::h();
55 using namespace A::inner;
57 using namespace B;
58 using namespace B::inner;
59 B::f();
60 f();
62 using namespace C;
64 D::f();
67 int use_header() { return foo + bar::baz(); }
69 #elif defined(USER)
70 import p2;
71 import "header.h";
73 void use() {
74 // namespace A is implicitly exported by the export of A::g.
75 A::f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}}
76 // expected-note@* {{declaration here is not visible}}
77 A::g();
78 A::h(); // expected-error {{declaration of 'h' must be imported from module 'p2' before it is required}}
79 // expected-note@* {{declaration here is not visible}}
80 using namespace A::inner; // expected-error {{declaration of 'inner' must be imported from module 'p2' before it is required}}
81 // expected-note@* {{declaration here is not visible}}
83 // namespace B and B::inner are explicitly exported
84 using namespace B;
85 using namespace B::inner;
86 B::f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}}
87 // expected-note@* {{declaration here is not visible}}
88 f(); // expected-error {{declaration of 'f' must be imported from module 'p2' before it is required}}
89 // expected-note@* {{declaration here is not visible}}
91 // namespace C is not exported
92 using namespace C; // expected-error {{declaration of 'C' must be imported from module 'p2' before it is required}}
93 // expected-note@* {{declaration here is not visible}}
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}}
100 int use_header() { return foo + bar::baz(); }
102 #else
103 #error unknown mode
104 #endif