[clang-tools-extra] [clang-tidy] Redirect hicpp-ignored-remove-result to bugprone-unused-return-value (PR #184547)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 8 16:54:04 PDT 2026
https://github.com/IamYJLee updated https://github.com/llvm/llvm-project/pull/184547
>From 38a8cc19f3c5441334f5e4bba30a37b3bb6b6883 Mon Sep 17 00:00:00 2001
From: LeeYoungJoon <dog3hk.dev at gmail.com>
Date: Wed, 4 Mar 2026 14:03:26 +0900
Subject: [PATCH 1/2] [clang-tidy] Redirect hicpp-ignored-remove-result to
bugprone-unused-return-value
---
.../clang-tidy/hicpp/CMakeLists.txt | 1 -
.../clang-tidy/hicpp/HICPPTidyModule.cpp | 14 ++++++--
.../hicpp/IgnoredRemoveResultCheck.cpp | 30 -----------------
.../hicpp/IgnoredRemoveResultCheck.h | 32 -------------------
clang-tools-extra/docs/ReleaseNotes.rst | 5 +++
.../checks/bugprone/unused-return-value.rst | 4 +++
.../checks/hicpp/ignored-remove-result.rst | 25 +++------------
.../docs/clang-tidy/checks/list.rst | 2 +-
8 files changed, 27 insertions(+), 86 deletions(-)
delete mode 100644 clang-tools-extra/clang-tidy/hicpp/IgnoredRemoveResultCheck.cpp
delete mode 100644 clang-tools-extra/clang-tidy/hicpp/IgnoredRemoveResultCheck.h
diff --git a/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt b/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt
index 9179e5dea4ea9..e8401e750642d 100644
--- a/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt
@@ -6,7 +6,6 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangTidyHICPPModule STATIC
ExceptionBaseclassCheck.cpp
HICPPTidyModule.cpp
- IgnoredRemoveResultCheck.cpp
MultiwayPathsCoveredCheck.cpp
SignedBitwiseCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index a4601d9cdde9f..8bebc317aaeba 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -9,6 +9,7 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../bugprone/UndelegatedConstructorCheck.h"
+#include "../bugprone/UnusedReturnValueCheck.h"
#include "../bugprone/UseAfterMoveCheck.h"
#include "../cppcoreguidelines/AvoidGotoCheck.h"
#include "../cppcoreguidelines/NoMallocCheck.h"
@@ -36,7 +37,6 @@
#include "../readability/NamedParameterCheck.h"
#include "../readability/UppercaseLiteralSuffixCheck.h"
#include "ExceptionBaseclassCheck.h"
-#include "IgnoredRemoveResultCheck.h"
#include "MultiwayPathsCoveredCheck.h"
#include "SignedBitwiseCheck.h"
@@ -57,7 +57,7 @@ class HICPPModule : public ClangTidyModule {
"hicpp-deprecated-headers");
CheckFactories.registerCheck<ExceptionBaseclassCheck>(
"hicpp-exception-baseclass");
- CheckFactories.registerCheck<IgnoredRemoveResultCheck>(
+ CheckFactories.registerCheck<bugprone::UnusedReturnValueCheck>(
"hicpp-ignored-remove-result");
CheckFactories.registerCheck<MultiwayPathsCoveredCheck>(
"hicpp-multiway-paths-covered");
@@ -110,6 +110,16 @@ class HICPPModule : public ClangTidyModule {
CheckFactories.registerCheck<cppcoreguidelines::ProTypeVarargCheck>(
"hicpp-vararg");
}
+
+ ClangTidyOptions getModuleOptions() override {
+ ClangTidyOptions Options;
+ ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
+ Opts["hicpp-ignored-remove-result.CheckedFunctions"] =
+ "::std::remove$;::std::remove_if$;::std::unique$";
+ Opts["hicpp-ignored-remove-result.CheckedReturnTypes"] = "";
+ Opts["hicpp-ignored-remove-result.AllowCastToVoid"] = "true";
+ return Options;
+ }
};
} // namespace
diff --git a/clang-tools-extra/clang-tidy/hicpp/IgnoredRemoveResultCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/IgnoredRemoveResultCheck.cpp
deleted file mode 100644
index 5321fd8d5b1c2..0000000000000
--- a/clang-tools-extra/clang-tidy/hicpp/IgnoredRemoveResultCheck.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "IgnoredRemoveResultCheck.h"
-
-namespace clang::tidy::hicpp {
-
-IgnoredRemoveResultCheck::IgnoredRemoveResultCheck(llvm::StringRef Name,
- ClangTidyContext *Context)
- : UnusedReturnValueCheck(Name, Context,
- {
- "::std::remove$",
- "::std::remove_if$",
- "::std::unique$",
- }) {
- // The constructor for ClangTidyCheck needs to have been called
- // before we can access options via Options.get().
- AllowCastToVoid = Options.get("AllowCastToVoid", true);
-}
-
-void IgnoredRemoveResultCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
- Options.store(Opts, "AllowCastToVoid", AllowCastToVoid);
-}
-
-} // namespace clang::tidy::hicpp
diff --git a/clang-tools-extra/clang-tidy/hicpp/IgnoredRemoveResultCheck.h b/clang-tools-extra/clang-tidy/hicpp/IgnoredRemoveResultCheck.h
deleted file mode 100644
index 07e624e446403..0000000000000
--- a/clang-tools-extra/clang-tidy/hicpp/IgnoredRemoveResultCheck.h
+++ /dev/null
@@ -1,32 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_IGNOREDREMOVERESULTCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_IGNOREDREMOVERESULTCHECK_H
-
-#include "../bugprone/UnusedReturnValueCheck.h"
-
-namespace clang::tidy::hicpp {
-
-/// Ensure that the result of std::remove, std::remove_if and std::unique
-/// are not ignored according to rule 17.5.1.
-///
-/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/hicpp/ignored-remove-result.html
-class IgnoredRemoveResultCheck : public bugprone::UnusedReturnValueCheck {
-public:
- IgnoredRemoveResultCheck(StringRef Name, ClangTidyContext *Context);
- bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
- return LangOpts.CPlusPlus;
- }
- void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
-};
-
-} // namespace clang::tidy::hicpp
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_IGNOREDREMOVERESULTCHECK_H
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 6e1a116a30bf8..cb46c7ee6b96d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -156,6 +156,11 @@ New checks
New check aliases
^^^^^^^^^^^^^^^^^
+- Renamed :doc:`hicpp-ignored-remove-result
+ <clang-tidy/checks/hicpp/ignored-remove-result>`
+ to :doc:`bugprone-unused-return-value
+ <clang-tidy/checks/bugprone/unused-return-value>`.
+ The `hicpp-ignored-remove-result` name is kept as an alias.
- Renamed :doc:`hicpp-no-assembler <clang-tidy/checks/hicpp/no-assembler>`
to :doc:`portability-no-assembler
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
index 725403a6eb818..183c828808fc6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -67,3 +67,7 @@ Options
:doc:`cert-err33-c <../cert/err33-c>` is an alias of this check that checks a
fixed and large set of standard library functions.
+
+:doc:`hicpp-ignored-remove-result <../hicpp/ignored-remove-result>` is an
+alias of this check that checks a restricted set of functions:
+``std::remove``, ``std::remove_if``, and ``std::unique``.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
index 1c749b169828e..622e4b79d20be 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/ignored-remove-result.rst
@@ -1,25 +1,10 @@
.. title:: clang-tidy - hicpp-ignored-remove-result
+.. meta::
+ :http-equiv=refresh: 5;URL=../bugprone/unused-return-value.html
hicpp-ignored-remove-result
===========================
-Ensure that the result of ``std::remove``, ``std::remove_if`` and ``std::unique``
-are not ignored according to
-`rule 17.5.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-rules>`_.
-
-The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
-of ``std::unique`` operate by swapping or moving elements of the range they are
-operating over. On completion, they return an iterator to the last valid
-element. In the majority of cases the correct behavior is to use this result as
-the first operand in a call to ``std::erase``.
-
-This check is a subset of :doc:`bugprone-unused-return-value
-<../bugprone/unused-return-value>`
-and depending on used options it can be superfluous to enable both checks.
-
-Options
--------
-
-.. option:: AllowCastToVoid
-
- Controls whether casting return values to ``void`` is permitted. Default: `true`.
+The hicpp-ignored-remove-result check is an alias, please see
+:doc:`bugprone-unused-return-value <../bugprone/unused-return-value>`
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 068431fb5c94c..8e94ff964af1b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -241,7 +241,6 @@ Clang-Tidy Checks
:doc:`google-runtime-operator <google/runtime-operator>`,
:doc:`google-upgrade-googletest-case <google/upgrade-googletest-case>`, "Yes"
:doc:`hicpp-exception-baseclass <hicpp/exception-baseclass>`,
- :doc:`hicpp-ignored-remove-result <hicpp/ignored-remove-result>`,
:doc:`hicpp-multiway-paths-covered <hicpp/multiway-paths-covered>`,
:doc:`hicpp-signed-bitwise <hicpp/signed-bitwise>`,
:doc:`linuxkernel-must-check-errs <linuxkernel/must-check-errs>`,
@@ -602,6 +601,7 @@ Check aliases
:doc:`hicpp-deprecated-headers <hicpp/deprecated-headers>`, :doc:`modernize-deprecated-headers <modernize/deprecated-headers>`, "Yes"
:doc:`hicpp-explicit-conversions <hicpp/explicit-conversions>`, :doc:`google-explicit-constructor <google/explicit-constructor>`, "Yes"
:doc:`hicpp-function-size <hicpp/function-size>`, :doc:`readability-function-size <readability/function-size>`,
+ :doc:`hicpp-ignored-remove-result <hicpp/ignored-remove-result>`, :doc:`bugprone-unused-return-value <bugprone/unused-return-value>`,
:doc:`hicpp-invalid-access-moved <hicpp/invalid-access-moved>`, :doc:`bugprone-use-after-move <bugprone/use-after-move>`,
:doc:`hicpp-member-init <hicpp/member-init>`, :doc:`cppcoreguidelines-pro-type-member-init <cppcoreguidelines/pro-type-member-init>`, "Yes"
:doc:`hicpp-move-const-arg <hicpp/move-const-arg>`, :doc:`performance-move-const-arg <performance/move-const-arg>`, "Yes"
>From 02ed0475999ad95dd6cf29acf2992435713ea0d8 Mon Sep 17 00:00:00 2001
From: LeeYoungJoon <dog3hk.dev at gmail.com>
Date: Wed, 4 Mar 2026 16:14:25 +0900
Subject: [PATCH 2/2] [clang-tidy] Address review feedback: add ^ anchors to
regex patterns and document AllowCastToVoid default
---
clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp | 2 +-
.../docs/clang-tidy/checks/bugprone/unused-return-value.rst | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 8bebc317aaeba..3eb6d5de39d04 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -115,7 +115,7 @@ class HICPPModule : public ClangTidyModule {
ClangTidyOptions Options;
ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
Opts["hicpp-ignored-remove-result.CheckedFunctions"] =
- "::std::remove$;::std::remove_if$;::std::unique$";
+ "^::std::remove$;^::std::remove_if$;^::std::unique$";
Opts["hicpp-ignored-remove-result.CheckedReturnTypes"] = "";
Opts["hicpp-ignored-remove-result.AllowCastToVoid"] = "true";
return Options;
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
index 183c828808fc6..3e7c51a9b1ac4 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -71,3 +71,4 @@ fixed and large set of standard library functions.
:doc:`hicpp-ignored-remove-result <../hicpp/ignored-remove-result>` is an
alias of this check that checks a restricted set of functions:
``std::remove``, ``std::remove_if``, and ``std::unique``.
+The `AllowCastToVoid` option is set to `true` by default.
More information about the cfe-commits
mailing list