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