https://github.com/localspook updated https://github.com/llvm/llvm-project/pull/183638
>From e60a0befdcbf980a6693ebea67cde92536a11d4a Mon Sep 17 00:00:00 2001 From: Victor Chernyakin <[email protected]> Date: Thu, 26 Feb 2026 15:10:50 -0800 Subject: [PATCH 1/2] [clang-tidy] Teach `misc-unused-using-decls` that exported using-decls aren't unused --- .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 6 ++ clang-tools-extra/docs/ReleaseNotes.rst | 4 ++ .../misc/unused-using-decls-module.cpp | 69 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-module.cpp diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp index 6d1b253530628..cb5eee4d0dd9c 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp @@ -99,6 +99,12 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) { if (isa<FunctionDecl>(Using->getDeclContext())) return; + // Ignore exported using-decls. + if (Using->hasOwningModule() && + Using->getModuleOwnershipKind() <= + Decl::ModuleOwnershipKind::VisibleWhenImported) + return; + UsingDeclContext Context(Using); Context.UsingDeclRange = CharSourceRange::getCharRange( Using->getBeginLoc(), diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index cf8dd0dba9f12..01c1058b4bdfa 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -208,6 +208,10 @@ Changes in existing checks - Fixed false positive where an array of pointers to ``const`` was incorrectly diagnosed as allowing the pointee to be made ``const``. +- Improved :doc:`misc-unused-using-decls + <clang-tidy/checks/misc/unused-using-decls>` to not diagnose using + declarations as unused if they're exported from a module. + - Improved :doc:`modernize-pass-by-value <clang-tidy/checks/modernize/pass-by-value>` check by adding `IgnoreMacros` option to suppress warnings in macros. diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-module.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-module.cpp new file mode 100644 index 0000000000000..2ba06238bf715 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-module.cpp @@ -0,0 +1,69 @@ +// RUN: %check_clang_tidy -std=c++20-or-later %s misc-unused-using-decls %t -- --fix-notes + +module; + +namespace n { + +struct S {}; + +} // namespace n + +using n::S; // n::S +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'S' is unused +// CHECK-FIXES: // n::S + +export module foo; + +struct A {}; +export struct B {}; +export struct C {}; +export struct D {}; + +namespace ns1 { + +using ::A; // ns1::A +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: using decl 'A' is unused +// CHECK-FIXES: // ns1::A + +// If the decl isn't exported, it's unused, even if the underlying struct is exported. +using ::B; // ns1::B +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: using decl 'B' is unused +// CHECK-FIXES: // ns1::B + +export using ::C; + +export { + +using ::D; + +} + +} // namespace n + +export namespace ns2 { + +using ::B; + +} // namespace ns2 + +export { + +namespace ns3 { + +using ::B; + +} // namespace ns3 + +} + +export namespace ns3 { + +struct E {}; + +} // namespace ns3 + +module :private; + +using ns3::E; // ns3::E +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: using decl 'E' is unused +// CHECK-FIXES: // ns3::E >From 9514793dc8d8fa85b043cdfb90100dc7d2f03b54 Mon Sep 17 00:00:00 2001 From: Victor Chernyakin <[email protected]> Date: Thu, 26 Feb 2026 15:58:44 -0800 Subject: [PATCH 2/2] Use double backticks Co-authored-by: EugeneZelenko <[email protected]> --- clang-tools-extra/docs/ReleaseNotes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 01c1058b4bdfa..6a14990d98905 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -209,7 +209,7 @@ Changes in existing checks incorrectly diagnosed as allowing the pointee to be made ``const``. - Improved :doc:`misc-unused-using-decls - <clang-tidy/checks/misc/unused-using-decls>` to not diagnose using + <clang-tidy/checks/misc/unused-using-decls>` to not diagnose ``using`` declarations as unused if they're exported from a module. - Improved :doc:`modernize-pass-by-value _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
