1 // RUN: %clang_cc1 -std=c++2a -verify %s
2 // RUN: %clang_cc1 -std=c++2a -verify -DNO_GLOBAL_FRAG %s
3 // RUN: %clang_cc1 -std=c++2a -verify -DNO_MODULE_DECL %s
4 // RUN: %clang_cc1 -std=c++2a -verify -DNO_PRIVATE_FRAG %s
5 // RUN: %clang_cc1 -std=c++2a -verify -DNO_MODULE_DECL -DNO_PRIVATE_FRAG %s
6 // RUN: %clang_cc1 -std=c++2a -verify -DNO_GLOBAL_FRAG -DNO_PRIVATE_FRAG %s
7 // RUN: %clang_cc1 -std=c++2a -verify -DNO_GLOBAL_FRAG -DNO_MODULE_DECL %s
8 // RUN: %clang_cc1 -std=c++2a -verify -DNO_GLOBAL_FRAG -DNO_MODULE_DECL -DNO_PRIVATE_FRAG %s
9 // RUN: %clang_cc1 -std=c++2a -verify -DEXPORT_FRAGS %s
10 
11 #ifndef NO_GLOBAL_FRAG
12 #ifdef EXPORT_FRAGS
13 export // expected-error {{global module fragment cannot be exported}}
14 #endif
15 module;
16 #ifdef NO_MODULE_DECL
17 // expected-error@-2 {{missing 'module' declaration at end of global module fragment introduced here}}
18 #endif
19 #endif
20 
21 extern int a; // #a1
22 
23 #ifndef NO_MODULE_DECL
24 export module Foo;
25 #ifdef NO_GLOBAL_FRAG
26 // expected-error@-2 {{module declaration must occur at the start of the translation unit}}
27 // expected-note@1 {{add 'module;' to the start of the file to introduce a global module fragment}}
28 #endif
29 
30 // expected-error@#a2 {{declaration of 'a' in module Foo follows declaration in the global module}}
31 // expected-note@#a1 {{previous decl}}
32 #endif
33 
34 int a; // #a2
35 extern int b;
36 
37 module; // expected-error {{'module;' introducing a global module fragment can appear only at the start of the translation unit}}
38 
39 #ifndef NO_PRIVATE_FRAG
40 #ifdef EXPORT_FRAGS
41 export // expected-error {{private module fragment cannot be exported}}
42 #endif
43 module :private; // #priv-frag
44 #ifdef NO_MODULE_DECL
45 // expected-error@-2 {{private module fragment declaration with no preceding module declaration}}
46 #endif
47 #endif
48 
49 int b; // ok
50 
51 
52 #ifndef NO_PRIVATE_FRAG
53 #ifndef NO_MODULE_DECL
54 module :private; // expected-error {{private module fragment redefined}}
55 // expected-note@#priv-frag {{previous definition is here}}
56 #endif
57 #endif
58