Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / module / module.import / p2.cpp
blob0c02d253f3a898f9c200aba35438d9c7fa565cf4
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4 // RUN: %clang_cc1 -std=c++20 %t/impl.cppm -emit-module-interface -o %t/M-impl.pcm
5 // RUN: %clang_cc1 -std=c++20 %t/M.cppm -emit-module-interface -fprebuilt-module-path=%t -o %t/M.pcm
6 // RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t -verify -fsyntax-only
7 // RUN: %clang_cc1 -std=c++20 %t/UseInPartA.cppm -fprebuilt-module-path=%t -verify -fsyntax-only
8 // RUN: %clang_cc1 -std=c++20 %t/UseInAnotherModule.cppm -fprebuilt-module-path=%t -verify -fsyntax-only
9 // RUN: %clang_cc1 -std=c++20 %t/Private.cppm -emit-module-interface -fprebuilt-module-path=%t -o %t/A.pcm
10 // RUN: %clang_cc1 -std=c++20 %t/TryUseFromPrivate.cpp -fprebuilt-module-path=%t -verify -fsyntax-only
11 // RUN: %clang_cc1 -std=c++20 %t/Global.cppm -emit-module-interface -fprebuilt-module-path=%t -o %t/C.pcm
12 // RUN: %clang_cc1 -std=c++20 %t/UseGlobal.cpp -fprebuilt-module-path=%t -verify -fsyntax-only
14 //--- impl.cppm
15 module M:impl;
16 class A {};
18 //--- M.cppm
19 export module M;
20 import :impl;
21 export A f();
23 //--- Use.cpp
24 import M;
25 void test() {
26 A a; // expected-error {{declaration of 'A' must be imported from module 'M:impl'}}
27 // expected-error@-1 {{definition of 'A' must be imported from module 'M:impl'}} expected-error@-1 {{}}
28 // expected-note@impl.cppm:2 {{declaration here is not visible}}
29 // expected-note@impl.cppm:2 {{definition here is not reachable}} expected-note@impl.cppm:2 {{}}
32 //--- UseInPartA.cppm
33 // expected-no-diagnostics
34 export module M:partA;
35 import :impl;
36 void test() {
37 A a;
40 //--- UseInAnotherModule.cppm
41 export module B;
42 import M;
43 void test() {
44 A a; // expected-error {{declaration of 'A' must be imported from module 'M:impl'}}
45 // expected-error@-1 {{definition of 'A' must be imported from module 'M:impl'}} expected-error@-1 {{}}
46 // expected-note@impl.cppm:2 {{declaration here is not visible}}
47 // expected-note@impl.cppm:2 {{definition here is not reachable}} expected-note@impl.cppm:2 {{}}
50 //--- Private.cppm
51 export module A;
52 module :private;
54 class A {};
55 void test() {
56 A a;
59 //--- TryUseFromPrivate.cpp
61 import A;
62 void test() {
63 A a; // expected-error {{unknown type name 'A'}}
66 //--- Global.cppm
67 module;
68 class A{};
69 export module C;
70 void test() {
71 A a;
74 //--- UseGlobal.cpp
75 import C;
76 void test() {
77 A a; // expected-error {{'A' must be declared before it is used}}
78 // expected-note@Global.cppm:2 {{declaration here is not visible}}