| 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 {{declaration of 'not_exported' must be imported from module 'A' before it is required}} |
| 66 |
// [email protected]:19 {{declaration here is not visible}} |
| 67 |
#endif |
| 68 |
|
| 69 |
internal = 1; |
| 70 |
#ifndef IMPLEMENTATION |
| 71 |
// expected-error@-2 {{declaration of 'internal' must be imported from module 'A' before it is required}} |
| 72 |
// [email protected]:20 {{declaration here is not visible}} |
| 73 |
#endif |
| 74 |
|
| 75 |
not_exported_private = 1; |
| 76 |
#ifndef IMPLEMENTATION |
| 77 |
// FIXME: should not be visible here |
| 78 |
// expected-error@-3 {{undeclared identifier}} |
| 79 |
#endif |
| 80 |
|
| 81 |
internal_private = 1; |
| 82 |
#ifndef IMPLEMENTATION |
| 83 |
// FIXME: should not be visible here |
| 84 |
// expected-error@-3 {{undeclared identifier}} |
| 85 |
#endif |
| 86 |
} |
| 87 |
|
| 88 |
#endif |