[clang] [clang][modules] Make -fmodules-decluse work on the public/private pair of modules (PR #192585)
Takuto Ikuta via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 21:53:43 PDT 2026
================
@@ -0,0 +1,69 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fimplicit-module-maps -fmodules-cache-path=%t -fmodules-strict-decluse -fmodule-name=lib_Private -I %t %t/lib.cpp -verify
+
+//--- module.modulemap
+// This simulates a modulemap that might reasonably be generated by a build system for something resembling the following.
+// This can be used to perform strict dependency checking to ensure that your build graph is correctly declared.
+// cc_library(
+// name = "lib",
+// # .cpp file in sources -> generate a compilation action with -fmodule-name=lib_Private
+// # .h file in sources -> "textual header" in private modulemap
+// sources = ["lib.cpp"],
+// # headers -> "textual header" in public modulemap
+// headers = ["lib.h"],
+// # implementation_dep -> "use" in private modulemap
+// implementation_deps = [":impl_dep"]
+// # dep -> "use" in private and public modulemap
+// deps = [":direct"],
+// )
+// cc_library(name = "direct", headers = ["direct.h"], deps = [":indirect"], ...)
+// cc_library(name = "indirect", headers = ["indirect.h"], ..)
+// cc_library(name = "impl_dep", headers = ["impl_dep.h"], ...)
+module lib_Private {
+ use impl_dep
+ use lib
+ use direct
+}
+
+module lib {
+ textual header "lib.h"
+ use direct
+}
+
+
+module impl_dep {
+ textual header "impl_dep.h"
+}
+
+module direct {
+ textual header "direct.h"
+ use indirect
+}
+
+module indirect {
+ textual header "indirect.h"
+}
+
+//--- impl_dep.h
+void impl_dep();
+//--- direct.h
+#include "impl_dep.h" // OK (it should only verify the main module).
+void direct();
+//--- indirect.h
+void indirect();
+//--- not_module.h
+void not_module();
+
+//--- lib.cpp
+#include "lib.h"
+#include "direct.h" // OK
+#include "indirect.h" // expected-error {{module lib_Private does not directly depend on a module exporting 'indirect.h', which is part of indirectly-used module indirect}}
+#include "impl_dep.h" // OK
+#include "not_module.h" // expected-error {{lib_Private does not depend on a module exporting 'not_module.h'}}
----------------
atetubou wrote:
```suggestion
#include "not_module.h" // expected-error {{module lib_Private does not depend on a module exporting 'not_module.h'}}
```
https://github.com/llvm/llvm-project/pull/192585
More information about the cfe-commits
mailing list