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=A=%t.pcm -DIMPLEMENTATION %s -verify -fno-modules-error-recovery 9 // RUN: %clang_cc1 -std=c++2a -I%t -fmodule-file=A=%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 {{use of undeclared identifier 'in_header'}} 33 // expected-note@* {{not visible}} 34 35 global_module_fragment = 1; // expected-error {{use of undeclared identifier 'global_module_fragment'}} 36 37 exported = 1; // expected-error {{use of undeclared identifier 'exported'}} 38 39 not_exported = 1; // expected-error {{use of undeclared identifier 'not_exported'}} 40 41 // FIXME: We need better diagnostic message for static variable. 42 internal = 1; // expected-error {{use of undeclared identifier 'internal'}} 43 44 not_exported_private = 1; // expected-error {{undeclared identifier}} 45 46 internal_private = 1; // expected-error {{undeclared identifier}} 47 } 48 49 #ifdef IMPLEMENTATION 50 module A; 51 #else 52 import A; 53 #endif 54 55 void test_late() { 56 in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}} 57 // expected-note@* {{not visible}} 58 59 global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}} 60 61 exported = 1; 62 63 not_exported = 1; 64 #ifndef IMPLEMENTATION 65 // expected-error@-2 {{use of undeclared identifier 'not_exported'; did you mean 'exported'?}} 66 // expected-note@p2.cpp:18 {{'exported' declared here}} 67 #endif 68 69 internal = 1; // expected-error {{use of undeclared identifier 'internal'}} 70 71 not_exported_private = 1; 72 #ifndef IMPLEMENTATION 73 // FIXME: should not be visible here 74 // expected-error@-3 {{undeclared identifier}} 75 #endif 76 77 internal_private = 1; // expected-error {{use of undeclared identifier 'internal_private'}} 78 } 79 80 #endif 81