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 int global_module_fragment;
15 export module A;
16 export int exported;
17 int not_exported;
18 static int internal;
19 
20 module :private;
21 int not_exported_private;
22 static int internal_private;
23 #else
24 
25 #ifdef IMPLEMENTATION
26 module;
27 #endif
28 
29 void test_early() {
30   in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
31   // expected-note@*{{previous}}
32 
33   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
34 
35   exported = 1; // expected-error {{must be imported from module 'A'}}
36   // [email protected]:16 {{previous}}
37 
38   not_exported = 1; // expected-error {{undeclared identifier}}
39 
40   internal = 1; // expected-error {{undeclared identifier}}
41 
42   not_exported_private = 1; // expected-error {{undeclared identifier}}
43 
44   internal_private = 1; // expected-error {{undeclared identifier}}
45 }
46 
47 #ifdef IMPLEMENTATION
48 module A;
49 #else
50 import A;
51 #endif
52 
53 void test_late() {
54   in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
55   // expected-note@*{{previous}}
56 
57   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
58 
59   exported = 1;
60 
61   not_exported = 1;
62 #ifndef IMPLEMENTATION
63   // expected-error@-2 {{undeclared identifier 'not_exported'; did you mean 'exported'}}
64   // [email protected]:16 {{declared here}}
65 #endif
66 
67   internal = 1;
68 #ifndef IMPLEMENTATION
69   // FIXME: should not be visible here
70   // expected-error@-3 {{undeclared identifier}}
71 #endif
72 
73   not_exported_private = 1;
74 #ifndef IMPLEMENTATION
75   // FIXME: should not be visible here
76   // expected-error@-3 {{undeclared identifier}}
77 #endif
78 
79   internal_private = 1;
80 #ifndef IMPLEMENTATION
81   // FIXME: should not be visible here
82   // expected-error@-3 {{undeclared identifier}}
83 #endif
84 }
85 
86 #endif
87