110 lines · cpp
1// RUN: rm -rf %t2// RUN: split-file %s %t3// RUN: %clang_cc1 -std=c++2a -I%t -emit-module-interface %t/interface.cppm -o %t.pcm4// RUN: %clang_cc1 -std=c++2a -I%t -fmodule-file=A=%t.pcm %t/implA.cppm -verify -fno-modules-error-recovery5// RUN: %clang_cc1 -std=c++2a -I%t -fmodule-file=A=%t.pcm %t/implB.cppm -verify -fno-modules-error-recovery6 7//--- foo.h8#ifndef FOO_H9#define FOO_H10extern int in_header;11#endif12 13//--- interface.cppm14module;15#include "foo.h"16// FIXME: The following need to be moved to a header file. The global module17// fragment is only permitted to contain preprocessor directives.18int global_module_fragment;19export module A;20export int exported;21int not_exported;22static int internal;23 24module :private;25int not_exported_private;26static int internal_private;27 28//--- implA.cppm29module;30 31void 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 49module A;50 51void test_late() {52 in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}53 // expected-note@* {{not visible}}54 55 global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}56 57 exported = 1;58 59 not_exported = 1;60 61 internal = 1; // expected-error {{use of undeclared identifier 'internal'}}62 63 not_exported_private = 1;64 65 internal_private = 1; // expected-error {{use of undeclared identifier 'internal_private'}}66}67 68//--- implB.cppm69module;70 71void test_early() {72 in_header = 1; // expected-error {{use of undeclared identifier 'in_header'}}73 // expected-note@* {{not visible}}74 75 global_module_fragment = 1; // expected-error {{use of undeclared identifier 'global_module_fragment'}}76 77 exported = 1; // expected-error {{use of undeclared identifier 'exported'}}78 79 not_exported = 1; // expected-error {{use of undeclared identifier 'not_exported'}}80 81 // FIXME: We need better diagnostic message for static variable.82 internal = 1; // expected-error {{use of undeclared identifier 'internal'}}83 84 not_exported_private = 1; // expected-error {{undeclared identifier}}85 86 internal_private = 1; // expected-error {{undeclared identifier}}87}88 89export module B;90import A;91 92void test_late() {93 in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}94 // expected-note@* {{not visible}}95 96 global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}97 98 exported = 1;99 100 not_exported = 1; // expected-error {{use of undeclared identifier 'not_exported'; did you mean 'exported'?}}101 // expected-note@* {{'exported' declared here}}102 103 internal = 1; // expected-error {{use of undeclared identifier 'internal'}}104 105 not_exported_private = 1;106 // FIXME: should not be visible here107 // expected-error@-2 {{undeclared identifier}}108 109 internal_private = 1; // expected-error {{use of undeclared identifier 'internal_private'}}110}