blob: 29122ec7dab5077ad64060c6f0ab1b778f9e46cd [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 '}}
Bruno Cardoso Lopes0ad31822017-05-11 06:20:07 +000020// expected-note@-3 {{unguarded header; consider using #ifdef guards or #pragma once}}
Richard Smith54f04402017-05-18 02:29:20 +000021// FIXME: We should drop the "header from" in this diagnostic.
22// expected-note-re@modules-ts.cppm:1 {{'{{.*}}modules-ts.cppm' included multiple times, additional include site in header from module 'foo'}}
Richard Smith8df390f2016-09-08 23:14:54 +000023#endif
24
25#if TEST == 0
26export {
27 int a;
28 int b;
29 constexpr int *p = &n;
30}
31export int c;
32
33namespace N {
34 export void f() {}
35}
36
37export struct T {} t;
38#elif TEST == 3
39int use_a = a; // expected-error {{declaration of 'a' must be imported from module 'foo' before it is required}}
40// expected-note@-13 {{previous}}
41
42#undef foo
43import foo;
44
45export {} // expected-error {{export declaration cannot be empty}}
46export { ; }
47export { static_assert(true); }
48
49// FIXME: These diagnostics are not very good.
50export import foo; // expected-error {{expected unqualified-id}}
51export { import foo; } // expected-error {{expected unqualified-id}}
52
53int use_b = b;
54int use_n = n; // FIXME: this should not be visible, because it is not exported
55
56extern int n;
57static_assert(&n == p); // FIXME: these are not the same entity
58#endif
59
60
61#if TEST == 1
62struct S {
63 export int n; // expected-error {{expected member name or ';'}}
64 export static int n; // expected-error {{expected member name or ';'}}
65};
66#endif
67
68// FIXME: Exports of declarations without external linkage are disallowed.
69// Exports of declarations with non-external-linkage types are disallowed.
Richard Smith3b660562016-09-26 21:27:23 +000070
71// Cannot export within another export. This isn't precisely covered by the
72// language rules right now, but (per personal correspondence between zygoloid
73// and gdr) is the intent.
74#if TEST == 1
75export {
76 extern "C++" {
77 namespace NestedExport {
78 export { // expected-error {{appears within another export}}
79 int q;
80 }
81 }
82 }
83}
84#endif