Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Modules / Reachability-Private.cpp
blob9a7c3ba231f179c6a2335c9991f75da793c89664
1 // Tests that the definition in private module fragment is not reachable to its users.
2 //
3 // RUN: rm -rf %t
4 // RUN: mkdir -p %t
5 // RUN: split-file %s %t
6 //
7 // RUN: %clang_cc1 -std=c++20 %t/Private.cppm -emit-module-interface \
8 // RUN: -o %t/Private.pcm
9 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp \
10 // RUN: -DTEST_BADINLINE -verify -fsyntax-only
12 //--- Private.cppm
13 export module Private;
14 #ifdef TEST_BADINLINE
15 inline void fn_m(); // expected-error {{un-exported inline function not defined before the private module fragment}}
16 // expected-note@Private.cppm:13 {{private module fragment begins here}}
17 #endif
18 static void fn_s();
19 export struct X;
21 export void g(X *x) {
22 fn_s(); // OK, call to static function in same translation unit
23 #ifdef TEST_BADINLINE
24 fn_m(); // fn_m is not OK.
25 #endif
27 export X *factory(); // OK
29 module :private;
30 struct X {}; // definition not reachable from importers of A
31 X *factory() {
32 return new X();
34 void fn_m() {}
35 void fn_s() {}
37 //--- Use.cpp
38 import Private;
39 void foo() {
40 X x; // expected-error 1+{{missing '#include'; 'X' must be defined before it is used}}
41 // expected-note@Private.cppm:18 1+{{definition here is not reachable}}
42 auto _ = factory();
43 auto *__ = factory();
44 X *___ = factory();
46 g(__);
47 g(___);
48 g(factory());