Debian Codegraph @

clang/test/SemaCXX/modules.cppm

raw
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4
5 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/test0.cpp -o %t/test0.pcm -verify
6 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/test1.cpp -o %t/test1.pcm -verify
7 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/test2.cpp -fmodule-file=foo=%t/test0.pcm -o %t/test2.pcm -verify
8 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/test3.cpp -fmodule-file=foo=%t/test0.pcm -o %t/test3.pcm -verify
9
10 //--- test0.cpp
11 // expected-no-diagnostics
12 export module foo;
13
14 static int m;
15
16 int n;
17
18 export {
19 int a;
20 int b;
21 constexpr int *p = &n;
22 }
23 export int c;
24
25 namespace N {
26 export void f() {}
27 } // namespace N
28
29 export struct T {
30 } t;
31
32 //--- test1.cpp
33 export module foo;
34
35 static int m;
36
37 int n;
38
39 struct S {
40 export int n; // expected-error {{expected member name or ';'}}
41 export static int n; // expected-error {{expected member name or ';'}}
42 };
43
44 int main() {} // expected-warning {{'main' never has module linkage}}
45
46 // FIXME: Exports of declarations without external linkage are disallowed.
47 // Exports of declarations with non-external-linkage types are disallowed.
48
49 // Cannot export within another export. This isn't precisely covered by the
50 // language rules right now, but (per personal correspondence between zygoloid
51 // and gdr) is the intent.
52 export { // expected-note {{export block begins here}}
53 extern "C++" {
54 namespace NestedExport {
55 export { // expected-error {{export declaration appears within another export declaration}}
56 int q;
57 }
58 } // namespace NestedExport
59 }
60 }
61
62 //--- test2.cpp
63 // expected-no-diagnostics
64 export module foo;
65
66 static int m;
67
68 int n;
69
70 //--- test3.cpp
71 export module bar;
72
73 extern "C++" int main() {}
74
75 static int m;
76
77 int n;
78
79 int use_a = a; // expected-error {{use of undeclared identifier 'a'}}
80
81 import foo; // expected-error {{imports must immediately follow the module declaration}}
82
83 export {}
84 export {
85 ; // No diagnostic after P2615R1 DR
86 }
87 export {
88 static_assert(true); // No diagnostic after P2615R1 DR
89 }
90
91 int use_b = b; // expected-error{{use of undeclared identifier 'b'}}
92 int use_n = n; // FIXME: this should not be visible, because it is not exported
93
94 extern int n;
95 static_assert(&n != p); // expected-error{{use of undeclared identifier 'p'}}