Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++1z -fmodules-ts -emit-module-interface %s -o %t.pcm -verify -DTEST=0 |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame^] | 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 |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 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 | |
Richard Smith | 81328ac | 2017-04-21 22:39:18 +0000 | [diff] [blame] | 10 | export module foo; |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame^] | 11 | #if TEST == 2 |
| 12 | // expected-error@-2 {{redefinition of module 'foo'}} |
| 13 | // expected-note@modules-ts.cppm:* {{loaded from}} |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 14 | #endif |
| 15 | |
| 16 | static int m; // ok, internal linkage, so no redefinition error |
| 17 | int n; |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame^] | 18 | #if TEST >= 2 |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 19 | // expected-error@-2 {{redefinition of '}} |
| 20 | // expected-note@-3 {{previous}} |
| 21 | #endif |
| 22 | |
| 23 | #if TEST == 0 |
| 24 | export { |
| 25 | int a; |
| 26 | int b; |
| 27 | constexpr int *p = &n; |
| 28 | } |
| 29 | export int c; |
| 30 | |
| 31 | namespace N { |
| 32 | export void f() {} |
| 33 | } |
| 34 | |
| 35 | export struct T {} t; |
| 36 | #elif TEST == 3 |
| 37 | int 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 |
| 41 | import foo; |
| 42 | |
| 43 | export {} // expected-error {{export declaration cannot be empty}} |
| 44 | export { ; } |
| 45 | export { static_assert(true); } |
| 46 | |
| 47 | // FIXME: These diagnostics are not very good. |
| 48 | export import foo; // expected-error {{expected unqualified-id}} |
| 49 | export { import foo; } // expected-error {{expected unqualified-id}} |
| 50 | |
| 51 | int use_b = b; |
| 52 | int use_n = n; // FIXME: this should not be visible, because it is not exported |
| 53 | |
| 54 | extern int n; |
| 55 | static_assert(&n == p); // FIXME: these are not the same entity |
| 56 | #endif |
| 57 | |
| 58 | |
| 59 | #if TEST == 1 |
| 60 | struct 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 Smith | 3b66056 | 2016-09-26 21:27:23 +0000 | [diff] [blame] | 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 |
| 73 | export { |
| 74 | extern "C++" { |
| 75 | namespace NestedExport { |
| 76 | export { // expected-error {{appears within another export}} |
| 77 | int q; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | #endif |