1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: echo '#ifndef FOO_H' > %t/foo.h
4 // RUN: echo '#define FOO_H' >> %t/foo.h
5 // RUN: echo 'extern int in_header;' >> %t/foo.h
6 // RUN: echo '#endif' >> %t/foo.h
7 // RUN: %clang_cc1 -std=c++2a -I%t -emit-module-interface -DINTERFACE %s -o %t.pcm
8 // RUN: %clang_cc1 -std=c++2a -I%t -fmodule-file=%t.pcm -DIMPLEMENTATION %s -verify -fno-modules-error-recovery
9 // RUN: %clang_cc1 -std=c++2a -I%t -fmodule-file=%t.pcm %s -verify -fno-modules-error-recovery
10 
11 #ifdef INTERFACE
12 module;
13 #include "foo.h"
14 // FIXME: The following need to be moved to a header file. The global module
15 // fragment is only permitted to contain preprocessor directives.
16 int global_module_fragment;
17 export module A;
18 export int exported;
19 int not_exported;
20 static int internal;
21 
22 module :private;
23 int not_exported_private;
24 static int internal_private;
25 #else
26 
27 #ifdef IMPLEMENTATION
28 module;
29 #endif
30 
31 void test_early() {
32   in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
33   // expected-note@*{{not visible}}
34 
35   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
36   // [email protected]:16 {{not visible}}
37 
38   exported = 1; // expected-error {{must be imported from module 'A'}}
39   // [email protected]:18 {{not visible}}
40 
41   not_exported = 1; // expected-error {{undeclared identifier}}
42 
43   internal = 1; // expected-error {{undeclared identifier}}
44 
45   not_exported_private = 1; // expected-error {{undeclared identifier}}
46 
47   internal_private = 1; // expected-error {{undeclared identifier}}
48 }
49 
50 #ifdef IMPLEMENTATION
51 module A;
52 #else
53 import A;
54 #endif
55 
56 void test_late() {
57   in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
58   // expected-note@*{{not visible}}
59 
60   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
61   // [email protected]:16 {{not visible}}
62 
63   exported = 1;
64 
65   not_exported = 1;
66 #ifndef IMPLEMENTATION
67   // expected-error@-2 {{undeclared identifier 'not_exported'; did you mean 'exported'}}
68   // [email protected]:18 {{declared here}}
69 #endif
70 
71   internal = 1;
72 #ifndef IMPLEMENTATION
73   // FIXME: should not be visible here
74   // expected-error@-3 {{undeclared identifier}}
75 #endif
76 
77   not_exported_private = 1;
78 #ifndef IMPLEMENTATION
79   // FIXME: should not be visible here
80   // expected-error@-3 {{undeclared identifier}}
81 #endif
82 
83   internal_private = 1;
84 #ifndef IMPLEMENTATION
85   // FIXME: should not be visible here
86   // expected-error@-3 {{undeclared identifier}}
87 #endif
88 }
89 
90 #endif
91