From 42413141641e26462a0d0c95f62b09fea5df78e9 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 15 May 2015 20:05:43 +0000 Subject: [modules] Add local submodule visibility support for declarations. With this change, enabling -fmodules-local-submodule-visibility results in name visibility rules being applied to submodules of the current module in addition to imported modules (that is, names no longer "leak" between submodules of the same top-level module). This also makes it much safer to textually include a non-modular library into a module: each submodule that textually includes that library will get its own "copy" of that library, and so the library becomes visible no matter which including submodule you import. llvm-svn: 237473 --- clang/test/Modules/submodule-visibility.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 clang/test/Modules/submodule-visibility.cpp (limited to 'clang/test/Modules/submodule-visibility.cpp') diff --git a/clang/test/Modules/submodule-visibility.cpp b/clang/test/Modules/submodule-visibility.cpp new file mode 100644 index 00000000000..c63d942cc9e --- /dev/null +++ b/clang/test/Modules/submodule-visibility.cpp @@ -0,0 +1,21 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DALLOW_NAME_LEAKAGE +// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DIMPORT +// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t -fmodule-name=x -I%S/Inputs/submodule-visibility -verify %s + +#include "a.h" +#include "b.h" + +#if ALLOW_NAME_LEAKAGE +// expected-no-diagnostics +#elif IMPORT +// expected-error@-6 {{could not build module 'x'}} +#else +// The use of -fmodule-name=x causes us to textually include the above headers. +// The submodule visibility rules are still applied in this case. +// +// expected-error@b.h:1 {{declaration of 'n' must be imported from module 'x.a'}} +// expected-note@a.h:1 {{here}} +#endif + +int k = n + m; // OK, a and b are visible here. -- cgit v1.2.3