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