Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Modules / cxx20-import-diagnostics-a.cpp
bloba5cf44ed82d5ff307fc9143fd62b8a797f510695
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
5 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu1.cpp \
6 // RUN: -o %t/B.pcm
8 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu2.cpp \
9 // RUN: -o %t/C.pcm
11 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu3.cpp \
12 // RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=C=%t/C.pcm -o %t/AOK1.pcm
14 // RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu4.cpp \
15 // RUN: -fmodule-file=AOK1=%t/AOK1.pcm -fmodule-file=B=%t/B.pcm \
16 // RUN: -fmodule-file=C=%t/C.pcm -o %t/tu_3.s -verify
18 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu5.cpp \
19 // RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=C=%t/C.pcm -o %t/BC.pcm -verify
21 // RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu6.cpp \
22 // RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=C=%t/C.pcm -o %t/tu_5.s -verify
24 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu7.cpp \
25 // RUN: -fmodule-file=B=%t/B.pcm -o %t/D.pcm -verify
27 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu8.cpp \
28 // RUN: -fmodule-file=B=%t/B.pcm -o %t/D.pcm -verify
30 // RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu9.cpp \
31 // RUN: -fmodule-file=B=%t/B.pcm -o %t/tu_8.s -verify
33 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu10.cpp \
34 // RUN: -o %t/B.pcm -verify
36 // RUN: %clang_cc1 -std=c++20 -emit-obj %t/import-diags-tu11.cpp \
37 // RUN: -fmodule-file=C=%t/C.pcm -o %t/impl.o
39 // Test diagnostics for incorrect module import sequences.
41 //--- import-diags-tu1.cpp
43 export module B;
45 int foo ();
47 // expected-no-diagnostics
49 //--- import-diags-tu2.cpp
51 export module C;
53 int bar ();
55 // expected-no-diagnostics
57 //--- import-diags-tu3.cpp
59 export module AOK1;
61 import B;
62 export import C;
64 export int theAnswer ();
66 // expected-no-diagnostics
68 //--- import-diags-tu4.cpp
70 module;
72 module AOK1;
74 export import C; // expected-error {{export declaration can only be used within a module purview}}
76 int theAnswer () { return 42; }
78 //--- import-diags-tu5.cpp
80 export module BC;
82 export import B;
84 int foo () { return 10; }
86 import C; // expected-error {{imports must immediately follow the module declaration}}
88 //--- import-diags-tu6.cpp
90 module B; // implicitly imports B.
92 int foo () { return 10; }
94 import C; // expected-error {{imports must immediately follow the module declaration}}
96 //--- import-diags-tu7.cpp
98 module;
99 // We can only have preprocessor directives here, which permits
100 // header units (include-translated or not) and named modules.
101 import B;
102 export module D;
104 int delta ();
105 // expected-no-diagnostics
107 //--- import-diags-tu8.cpp
109 export module D;
111 int delta ();
113 module :private;
115 import B; // expected-error {{imports must immediately follow the module declaration}}
117 //--- import-diags-tu9.cpp
119 module B;
121 import B; // expected-error {{import of module 'B' appears within its own implementation}}
123 //--- import-diags-tu10.cpp
125 export module B;
127 import B; // expected-error {{import of module 'B' appears within its own interface}}
129 //--- import-diags-tu11.cpp
131 int x;
133 import C;
135 int baz() { return 6174; }
137 // expected-no-diagnostics