diff --git a/clang-tools-extra/include-cleaner/test/Inputs/modules/a.h b/clang-tools-extra/include-cleaner/test/Inputs/modules/a.h new file mode 100644 --- /dev/null +++ b/clang-tools-extra/include-cleaner/test/Inputs/modules/a.h @@ -0,0 +1,2 @@ +#pragma once +class A {}; diff --git a/clang-tools-extra/include-cleaner/test/Inputs/modules/module.map b/clang-tools-extra/include-cleaner/test/Inputs/modules/module.map new file mode 100644 --- /dev/null +++ b/clang-tools-extra/include-cleaner/test/Inputs/modules/module.map @@ -0,0 +1,2 @@ +module XA { +} diff --git a/clang-tools-extra/include-cleaner/test/module.cpp b/clang-tools-extra/include-cleaner/test/module.cpp new file mode 100644 --- /dev/null +++ b/clang-tools-extra/include-cleaner/test/module.cpp @@ -0,0 +1,7 @@ +// RUN: cp %s %t.cpp +// RUN: clang-include-cleaner -edit %t.cpp -- -I%S/Inputs/modules -fimplicit-module-maps -fmodules-strict-decluse -fmodule-name=XA +// RUN: FileCheck --match-full-lines --check-prefix=EDIT %s < %t.cpp + +// Verify the tool still works on compilable-but-layering-violation code. +#include "a.h" +// EDIT-NOT: {{^}}#include "a.h"{{$}} diff --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp --- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp +++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp @@ -95,6 +95,15 @@ RecordedPP PP; PragmaIncludes PI; + bool BeginInvocation(CompilerInstance &CI) override { + // Disable the clang-module-based layering-violation checks. + // These checks emit errors for a compilable source code. We want the tool + // continue to be functional even on a layering-violation code. + CI.getLangOpts().ModulesDeclUse = false; + CI.getLangOpts().ModulesStrictDeclUse = false; + return true; + } + void ExecuteAction() override { auto &P = getCompilerInstance().getPreprocessor(); P.addPPCallbacks(PP.record(P));