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 -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 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 10export module foo; 11#if TEST == 2 12// expected-error@-2 {{redefinition of module 'foo'}} 13// [email protected]:* {{loaded from}} 14#endif 15 16static int m; // ok, internal linkage, so no redefinition error 17int n; 18#if TEST >= 2 19// expected-error@-2 {{redefinition of '}} 20// expected-note@-3 {{unguarded header; consider using #ifdef guards or #pragma once}} 21// [email protected]:1 {{'{{.*}}modules-ts.cppm' included multiple times, additional include site here}} 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. 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 74export { 75 extern "C++" { 76 namespace NestedExport { 77 export { // expected-error {{appears within another export}} 78 int q; 79 } 80 } 81 } 82} 83#endif 84