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 |
| 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 | |
| 10 | module 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 | |
| 17 | static int m; // ok, internal linkage, so no redefinition error |
| 18 | int n; |
| 19 | #if TEST == 3 |
| 20 | // expected-error@-2 {{redefinition of '}} |
| 21 | // expected-note@-3 {{previous}} |
| 22 | #endif |
| 23 | |
| 24 | #if TEST == 0 |
| 25 | export { |
| 26 | int a; |
| 27 | int b; |
| 28 | constexpr int *p = &n; |
| 29 | } |
| 30 | export int c; |
| 31 | |
| 32 | namespace N { |
| 33 | export void f() {} |
| 34 | } |
| 35 | |
| 36 | export struct T {} t; |
| 37 | #elif TEST == 3 |
| 38 | int 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 |
| 42 | import foo; |
| 43 | |
| 44 | export {} // expected-error {{export declaration cannot be empty}} |
| 45 | export { ; } |
| 46 | export { static_assert(true); } |
| 47 | |
| 48 | // FIXME: These diagnostics are not very good. |
| 49 | export import foo; // expected-error {{expected unqualified-id}} |
| 50 | export { import foo; } // expected-error {{expected unqualified-id}} |
| 51 | |
| 52 | int use_b = b; |
| 53 | int use_n = n; // FIXME: this should not be visible, because it is not exported |
| 54 | |
| 55 | extern int n; |
| 56 | static_assert(&n == p); // FIXME: these are not the same entity |
| 57 | #endif |
| 58 | |
| 59 | |
| 60 | #if TEST == 1 |
| 61 | struct 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 Smith | 3b66056 | 2016-09-26 21:27:23 +0000 | [diff] [blame] | 69 | |
| 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 |
| 74 | export { |
| 75 | extern "C++" { |
| 76 | namespace NestedExport { |
| 77 | export { // expected-error {{appears within another export}} |
| 78 | int q; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | #endif |