[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
Tue Mar 3 21:07:06 PST 2026
https://github.com/IamYJLee created https://github.com/llvm/llvm-project/pull/184547
Part of the work in https://github.com/llvm/llvm-project/issues/183462.
Closes https://github.com/llvm/llvm-project/issues/183518.
>From 3a5247d952124c82bc053fd5b6f630796d20d601 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] [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 | 6 ++++
.../checks/bugprone/unused-return-value.rst | 4 +++
.../checks/hicpp/ignored-remove-result.rst | 25 +++------------
.../docs/clang-tidy/checks/list.rst | 2 +-
8 files changed, 28 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 2f31d168e65c0..0a5858b36b7d2 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
NoAssemblerCheck.cpp
SignedBitwiseCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 2e0e64fbcd2a1..810ab17298fdb 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"
@@ -35,7 +36,6 @@
#include "../readability/NamedParameterCheck.h"
#include "../readability/UppercaseLiteralSuffixCheck.h"
#include "ExceptionBaseclassCheck.h"
-#include "IgnoredRemoveResultCheck.h"
#include "MultiwayPathsCoveredCheck.h"
#include "NoAssemblerCheck.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");
@@ -109,6 +109,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 10b5e41dd79ed..eb81c28ba21ce 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -151,6 +151,12 @@ 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.
+
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^
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 c475870ed7b31..60be130226684 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-no-assembler <hicpp/no-assembler>`,
:doc:`hicpp-signed-bitwise <hicpp/signed-bitwise>`,
@@ -601,6 +600,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"
More information about the cfe-commits
mailing list