1// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -o %t.pcm -verify -DTEST=0
2// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -o %t.pcm -verify -DTEST=1
3// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -fmodule-file=%t.pcm -o %t.pcm -verify -DTEST=2
4// RUN:     %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -fmodule-file=%t.pcm -o %t.pcm -verify -Dfoo=bar -DTEST=3
5
6#if TEST == 0
7// expected-no-diagnostics
8#endif
9
10export module foo;
11#if TEST == 2
12// expected-error@-2 {{redefinition of module 'foo'}}
13// [email protected]:* {{loaded from}}
14#endif
15
16static int m; // ok, internal linkage, so no redefinition error
17int n;
18#if TEST >= 2
19// expected-error@-2 {{redefinition of '}}
20// expected-note@-3 {{previous}}
21#endif
22
23#if TEST == 0
24export {
25  int a;
26  int b;
27  constexpr int *p = &n;
28}
29export int c;
30
31namespace N {
32  export void f() {}
33}
34
35export struct T {} t;
36#elif TEST == 3
37int use_a = a; // expected-error {{declaration of 'a' must be imported from module 'foo' before it is required}}
38// expected-note@-13 {{previous}}
39
40#undef foo
41import foo;
42
43export {} // expected-error {{export declaration cannot be empty}}
44export { ; }
45export { static_assert(true); }
46
47// FIXME: These diagnostics are not very good.
48export import foo; // expected-error {{expected unqualified-id}}
49export { import foo; } // expected-error {{expected unqualified-id}}
50
51int use_b = b;
52int use_n = n; // FIXME: this should not be visible, because it is not exported
53
54extern int n;
55static_assert(&n == p); // FIXME: these are not the same entity
56#endif
57
58
59#if TEST == 1
60struct S {
61  export int n; // expected-error {{expected member name or ';'}}
62  export static int n; // expected-error {{expected member name or ';'}}
63};
64#endif
65
66// FIXME: Exports of declarations without external linkage are disallowed.
67// Exports of declarations with non-external-linkage types are disallowed.
68
69// Cannot export within another export. This isn't precisely covered by the
70// language rules right now, but (per personal correspondence between zygoloid
71// and gdr) is the intent.
72#if TEST == 1
73export {
74  extern "C++" {
75    namespace NestedExport {
76      export { // expected-error {{appears within another export}}
77        int q;
78      }
79    }
80  }
81}
82#endif
83