xref: /llvm-project/clang/test/Modules/cxx20-10-1-ex2.cpp (revision c5e4afe6733c58e24023ede04275bbed3bde8240)
1 
2 // RUN: rm -rf %t
3 // RUN: mkdir -p %t
4 // RUN: split-file %s %t
5 
6 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu1.cpp \
7 // RUN:  -o %t/B_Y.pcm
8 //
9 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu2.cpp \
10 // RUN:     -fmodule-file=B:Y=%t/B_Y.pcm -o %t/B.pcm
11 //
12 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu3.cpp \
13 // RUN:     -o %t/B_X1.pcm -verify
14 //
15 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu4.cpp \
16 // RUN:     -fmodule-file=B=%t/B.pcm -fmodule-file=B:Y=%t/B_Y.pcm  -o %t/B_X2.pcm
17 //
18 // RUN: %clang_cc1 -std=c++20 -emit-obj %t/std10-1-ex2-tu5.cpp \
19 // RUN:     -fmodule-file=B=%t/B.pcm -fmodule-file=B:Y=%t/B_Y.pcm  -o %t/b_tu5.o
20 //
21 // RUN: %clang_cc1 -std=c++20 -S %t/std10-1-ex2-tu6.cpp \
22 // RUN:     -fmodule-file=B=%t/B.pcm -fmodule-file=B:Y=%t/B_Y.pcm  -o %t/b_tu6.s -verify
23 //
24 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu7.cpp \
25 // RUN:     -fmodule-file=B:X2=%t/B_X2.pcm -fmodule-file=B=%t/B.pcm \
26 // RUN:     -fmodule-file=B:Y=%t/B_Y.pcm   -o %t/B_X3.pcm -verify
27 
28 // Test again with reduced BMI.
29 // RUN: rm %t/B_X2.pcm %t/B.pcm %t/B_Y.pcm
30 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/std10-1-ex2-tu1.cpp \
31 // RUN:  -o %t/B_Y.pcm
32 //
33 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/std10-1-ex2-tu2.cpp \
34 // RUN:     -fmodule-file=B:Y=%t/B_Y.pcm -o %t/B.pcm
35 //
36 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/std10-1-ex2-tu3.cpp \
37 // RUN:     -o %t/B_X1.pcm -verify
38 //
39 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/std10-1-ex2-tu4.cpp \
40 // RUN:     -fmodule-file=B=%t/B.pcm -fmodule-file=B:Y=%t/B_Y.pcm  -o %t/B_X2.pcm
41 //
42 // RUN: %clang_cc1 -std=c++20 -emit-obj %t/std10-1-ex2-tu5.cpp \
43 // RUN:     -fmodule-file=B=%t/B.pcm -fmodule-file=B:Y=%t/B_Y.pcm  -o %t/b_tu5.o
44 //
45 // RUN: %clang_cc1 -std=c++20 -S %t/std10-1-ex2-tu6.cpp \
46 // RUN:     -fmodule-file=B=%t/B.pcm -fmodule-file=B:Y=%t/B_Y.pcm  -o %t/b_tu6.s -verify
47 //
48 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/std10-1-ex2-tu7.cpp \
49 // RUN:     -fmodule-file=B:X2=%t/B_X2.pcm -fmodule-file=B=%t/B.pcm \
50 // RUN:     -fmodule-file=B:Y=%t/B_Y.pcm   -o %t/B_X3.pcm -verify
51 
52 //--- std10-1-ex2-tu1.cpp
53 module B:Y;
54 int y();
55 // expected-no-diagnostics
56 
57 //--- std10-1-ex2-tu2.cpp
58 export module B;
59 import :Y;
60 int n = y();
61 // expected-no-diagnostics
62 
63 //--- std10-1-ex2-tu3.cpp
64 module B:X1; // does not implicitly import B
65 int &a = n;  // expected-error {{use of undeclared identifier }}
66 
67 //--- std10-1-ex2-tu4.cpp
68 module B:X2; // does not implicitly import B
69 import B;
70 int &b = n; // OK
71 // expected-no-diagnostics
72 
73 //--- std10-1-ex2-tu5.cpp
74 module B;   // implicitly imports B
75 int &c = n; // OK
76 // expected-no-diagnostics
77 
78 //--- std10-1-ex2-tu6.cpp
79 import B;
80 // error, n is module-local and this is not a module.
81 int &c = n; // expected-error {{use of undeclared identifier 'n'}}
82 
83 //--- std10-1-ex2-tu7.cpp
84 // expected-no-diagnostics
85 module B:X3; // does not implicitly import B
86 import :X2; // X2 is an implementation unit import B.
87 // According to [module.import]p7:
88 //   Additionally, when a module-import-declaration in a module unit of some
89 //   module M imports another module unit U of M, it also imports all
90 //   translation units imported by non-exported module-import-declarations in
91 //   the module unit purview of U.
92 //
93 // So B is imported in B:X3 due to B:X2 imported B. So n is visible here.
94 int &c = n;
95