96 lines · plain
1// RUN: rm -rf %t2// RUN: mkdir -p %t3// RUN: split-file %s %t4 5// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/test0.cpp -o %t/test0.pcm -verify6// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/test1.cpp -o %t/test1.pcm -verify7// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/test2.cpp -fmodule-file=foo=%t/test0.pcm -o %t/test2.pcm -verify8// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/test3.cpp -fmodule-file=foo=%t/test0.pcm -o %t/test3.pcm -verify9 10//--- test0.cpp11// expected-no-diagnostics12export module foo;13 14static int m;15 16int n;17 18export {19 int a;20 int b;21 constexpr int *p = &n;22}23export int c;24 25namespace N {26export void f() {}27} // namespace N28 29export struct T {30} t;31 32//--- test1.cpp33export module foo;34 35static int m;36 37int n;38 39struct S {40 export int n; // expected-error {{expected member name or ';'}}41 export static int n; // expected-error {{expected member name or ';'}}42};43 44int 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 the50// language rules right now, but (per personal correspondence between zygoloid51// and gdr) is the intent.52export { // 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 NestedExport59 }60}61 62//--- test2.cpp63// expected-no-diagnostics64export module foo;65 66static int m;67 68int n;69 70//--- test3.cpp71export module bar;72 73extern "C++" int main() {}74 75static int m;76 77int n;78 79int use_a = a; // expected-error {{use of undeclared identifier 'a'}}80 81import foo; // expected-error {{imports must immediately follow the module declaration}}82 83export {}84export {85 ; // No diagnostic after P2615R1 DR86}87export {88 static_assert(true); // No diagnostic after P2615R1 DR89}90 91int use_b = b; // expected-error{{use of undeclared identifier 'b'}}92int use_n = n; // FIXME: this should not be visible, because it is not exported93 94extern int n;95static_assert(&n != p); // expected-error{{use of undeclared identifier 'p'}}96