| 1 |
// RUN: rm -rf %t |
| 2 |
// RUN: split-file %s %t |
| 3 |
|
| 4 |
// RUN: %clang_cc1 -std=c++2a -verify %t/M.cppm |
| 5 |
// RUN: %clang_cc1 -std=c++2a -verify %t/NoGlobalFrag.cppm |
| 6 |
// RUN: %clang_cc1 -std=c++2a -verify %t/NoModuleDecl.cppm |
| 7 |
// RUN: %clang_cc1 -std=c++2a -verify %t/NoPrivateFrag.cppm |
| 8 |
// RUN: %clang_cc1 -std=c++2a -verify %t/NoModuleDeclAndNoPrivateFrag.cppm |
| 9 |
// RUN: %clang_cc1 -std=c++2a -verify %t/NoGlobalFragAndNoPrivateFrag.cppm |
| 10 |
// RUN: %clang_cc1 -std=c++2a -verify %t/NoGlobalFragAndNoModuleDecl.cppm |
| 11 |
// RUN: %clang_cc1 -std=c++2a -verify %t/NoGlobalFragAndNoModuleDeclAndNoPrivateFrag.cppm |
| 12 |
// RUN: %clang_cc1 -std=c++2a -verify %t/ExportFrags.cppm |
| 13 |
|
| 14 |
//--- M.cppm |
| 15 |
module; |
| 16 |
extern int a; // #a1 |
| 17 |
export module Foo; |
| 18 |
|
| 19 |
int a; // expected-error {{declaration of 'a' in module Foo follows declaration in the global module}} |
| 20 |
// expected-note@#a1 {{previous decl}} |
| 21 |
extern int b; |
| 22 |
|
| 23 |
module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} |
| 24 |
module :private; // #priv-frag |
| 25 |
int b; // ok |
| 26 |
module :private; // expected-error {{private module fragment redefined}} |
| 27 |
// expected-note@#priv-frag {{previous definition is here}} |
| 28 |
|
| 29 |
//--- NoGlobalFrag.cppm |
| 30 |
|
| 31 |
extern int a; // #a1 |
| 32 |
export module Foo; // expected-error {{module declaration must occur at the start of the translation unit}} |
| 33 |
// expected-note@-2 {{add 'module;' to the start of the file to introduce a global module fragment}} |
| 34 |
|
| 35 |
// expected-error@#a2 {{declaration of 'a' in module Foo follows declaration in the global module}} |
| 36 |
// expected-note@#a1 {{previous decl}} |
| 37 |
|
| 38 |
int a; // #a2 |
| 39 |
extern int b; |
| 40 |
module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} |
| 41 |
module :private; // #priv-frag |
| 42 |
int b; // ok |
| 43 |
module :private; // expected-error {{private module fragment redefined}} |
| 44 |
// expected-note@#priv-frag {{previous definition is here}} |
| 45 |
|
| 46 |
//--- NoModuleDecl.cppm |
| 47 |
module; // expected-error {{missing 'module' declaration at end of global module fragment introduced here}} |
| 48 |
extern int a; // #a1 |
| 49 |
int a; // #a2 |
| 50 |
extern int b; |
| 51 |
module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} |
| 52 |
module :private; // expected-error {{private module fragment declaration with no preceding module declaration}} |
| 53 |
int b; // ok |
| 54 |
|
| 55 |
//--- NoPrivateFrag.cppm |
| 56 |
module; |
| 57 |
extern int a; // #a1 |
| 58 |
export module Foo; |
| 59 |
|
| 60 |
// expected-error@#a2 {{declaration of 'a' in module Foo follows declaration in the global module}} |
| 61 |
// expected-note@#a1 {{previous decl}} |
| 62 |
int a; // #a2 |
| 63 |
extern int b; |
| 64 |
|
| 65 |
module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} |
| 66 |
int b; // ok |
| 67 |
|
| 68 |
|
| 69 |
//--- NoModuleDeclAndNoPrivateFrag.cppm |
| 70 |
module; // expected-error {{missing 'module' declaration at end of global module fragment introduced here}} |
| 71 |
extern int a; // #a1 |
| 72 |
int a; // #a2 |
| 73 |
extern int b; |
| 74 |
|
| 75 |
module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} |
| 76 |
|
| 77 |
int b; // ok |
| 78 |
|
| 79 |
//--- NoGlobalFragAndNoPrivateFrag.cppm |
| 80 |
extern int a; // #a1 |
| 81 |
export module Foo; // expected-error {{module declaration must occur at the start of the translation unit}} |
| 82 |
// expected-note@1 {{add 'module;' to the start of the file to introduce a global module fragment}} |
| 83 |
|
| 84 |
// expected-error@#a2 {{declaration of 'a' in module Foo follows declaration in the global module}} |
| 85 |
// expected-note@#a1 {{previous decl}} |
| 86 |
|
| 87 |
int a; // #a2 |
| 88 |
extern int b; |
| 89 |
|
| 90 |
module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} |
| 91 |
|
| 92 |
int b; // ok |
| 93 |
|
| 94 |
//--- NoGlobalFragAndNoModuleDecl.cppm |
| 95 |
extern int a; // #a1 |
| 96 |
int a; // #a2 |
| 97 |
extern int b; |
| 98 |
module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} |
| 99 |
module :private; // #priv-frag |
| 100 |
// expected-error@-1 {{private module fragment declaration with no preceding module declaration}} |
| 101 |
int b; // ok |
| 102 |
|
| 103 |
|
| 104 |
//--- NoGlobalFragAndNoModuleDeclAndNoPrivateFrag.cppm |
| 105 |
extern int a; // #a1 |
| 106 |
int a; // #a2 |
| 107 |
extern int b; |
| 108 |
|
| 109 |
module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} |
| 110 |
int b; // ok |
| 111 |
|
| 112 |
//--- ExportFrags.cppm |
| 113 |
export module; // expected-error {{global module fragment cannot be exported}} |
| 114 |
extern int a; // #a1 |
| 115 |
export module Foo; |
| 116 |
// expected-error@#a2 {{declaration of 'a' in module Foo follows declaration in the global module}} |
| 117 |
// expected-note@#a1 {{previous decl}} |
| 118 |
|
| 119 |
int a; // #a2 |
| 120 |
extern int b; |
| 121 |
|
| 122 |
module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}} |
| 123 |
|
| 124 |
module :private; // #priv-frag |
| 125 |
|
| 126 |
int b; // ok |
| 127 |
module :private; // expected-error {{private module fragment redefined}} |
| 128 |
// expected-note@#priv-frag {{previous definition is here}} |