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