blob: 16695f6463a822249a9157e1be3b523c63128e83 [file] [log] [blame]
Richard Smith8df390f2016-09-08 23:14:54 +00001// RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -o %t.pcm -verify -DTEST=0
Richard Smith145e15a2017-04-24 23:12:30 +00002// 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
Richard Smith8df390f2016-09-08 23:14:54 +00004// 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
Richard Smith81328ac2017-04-21 22:39:18 +000010export module foo;
Richard Smith145e15a2017-04-24 23:12:30 +000011#if TEST == 2
12// expected-error@-2 {{redefinition of module 'foo'}}
13// expected-note@modules-ts.cppm:* {{loaded from}}
Richard Smith8df390f2016-09-08 23:14:54 +000014#endif
15
16static int m; // ok, internal linkage, so no redefinition error
17int n;
Richard Smith145e15a2017-04-24 23:12:30 +000018#if TEST >= 2
Richard Smith8df390f2016-09-08 23:14:54 +000019// 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.
Richard Smith3b660562016-09-26 21:27:23 +000068
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