[clang-tools-extra] [clang-tidy] Rename hicpp-exception-baseclass to bugprone-exception-baseclass (PR #183474)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 2 19:50:18 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: LeeYoungJoon (IamYJLee)
<details>
<summary>Changes</summary>
Part of the work in https://github.com/llvm/llvm-project/issues/183462.
Closes https://github.com/llvm/llvm-project/issues/183463.
---
Full diff: https://github.com/llvm/llvm-project/pull/183474.diff
10 Files Affected:
- (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+3)
- (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1)
- (renamed) clang-tools-extra/clang-tidy/bugprone/StdExceptionBaseclassCheck.cpp (+5-5)
- (renamed) clang-tools-extra/clang-tidy/bugprone/StdExceptionBaseclassCheck.h (+8-8)
- (modified) clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt (-1)
- (modified) clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp (+2-2)
- (added) clang-tools-extra/docs/clang-tidy/checks/bugprone/std-exception-baseclass.rst (+26)
- (modified) clang-tools-extra/docs/clang-tidy/checks/hicpp/exception-baseclass.rst (+5-24)
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+2-1)
- (renamed) clang-tools-extra/test/clang-tidy/checkers/bugprone/std-exception-baseclass.cpp (+1-1)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 310184037afbd..c6a6eac988c1e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -76,6 +76,7 @@
#include "SizeofExpressionCheck.h"
#include "SpuriouslyWakeUpFunctionsCheck.h"
#include "StandaloneEmptyCheck.h"
+#include "StdExceptionBaseclassCheck.h"
#include "StdNamespaceModificationCheck.h"
#include "StringConstructorCheck.h"
#include "StringIntegerAssignmentCheck.h"
@@ -158,6 +159,8 @@ class BugproneModule : public ClangTidyModule {
CheckFactories.registerCheck<EasilySwappableParametersCheck>(
"bugprone-easily-swappable-parameters");
CheckFactories.registerCheck<EmptyCatchCheck>("bugprone-empty-catch");
+ CheckFactories.registerCheck<StdExceptionBaseclassCheck>(
+ "bugprone-std-exception-baseclass");
CheckFactories.registerCheck<ExceptionCopyConstructorThrowsCheck>(
"bugprone-exception-copy-constructor-throws");
CheckFactories.registerCheck<ExceptionEscapeCheck>(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 96ad671d03b39..f7f185d53b269 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -39,6 +39,7 @@ add_clang_library(clangTidyBugproneModule STATIC
InvalidEnumDefaultInitializationCheck.cpp
UnintendedCharOstreamOutputCheck.cpp
ReturnConstRefFromParameterCheck.cpp
+ StdExceptionBaseclassCheck.cpp
SuspiciousStringviewDataUsageCheck.cpp
SwitchMissingDefaultCaseCheck.cpp
IncDecInConditionsCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StdExceptionBaseclassCheck.cpp
similarity index 89%
rename from clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
rename to clang-tools-extra/clang-tidy/bugprone/StdExceptionBaseclassCheck.cpp
index 71b82875c09a0..24a11dd266f8e 100644
--- a/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StdExceptionBaseclassCheck.cpp
@@ -6,15 +6,15 @@
//
//===----------------------------------------------------------------------===//
-#include "ExceptionBaseclassCheck.h"
+#include "StdExceptionBaseclassCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::hicpp {
+namespace clang::tidy::bugprone {
-void ExceptionBaseclassCheck::registerMatchers(MatchFinder *Finder) {
+void StdExceptionBaseclassCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
cxxThrowExpr(
unless(has(expr(anyOf(isTypeDependent(), isValueDependent())))),
@@ -34,7 +34,7 @@ void ExceptionBaseclassCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-void ExceptionBaseclassCheck::check(const MatchFinder::MatchResult &Result) {
+void StdExceptionBaseclassCheck::check(const MatchFinder::MatchResult &Result) {
const auto *BadThrow = Result.Nodes.getNodeAs<CXXThrowExpr>("bad_throw");
assert(BadThrow && "Did not match the throw expression");
@@ -54,4 +54,4 @@ void ExceptionBaseclassCheck::check(const MatchFinder::MatchResult &Result) {
diag(TypeDecl->getBeginLoc(), "type defined here", DiagnosticIDs::Note);
}
-} // namespace clang::tidy::hicpp
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.h b/clang-tools-extra/clang-tidy/bugprone/StdExceptionBaseclassCheck.h
similarity index 61%
rename from clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.h
rename to clang-tools-extra/clang-tidy/bugprone/StdExceptionBaseclassCheck.h
index 800e7ac9663d5..42e96822b97d8 100644
--- a/clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/StdExceptionBaseclassCheck.h
@@ -6,21 +6,21 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTIONBASECLASSCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTIONBASECLASSCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STDEXCEPTIONBASECLASSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STDEXCEPTIONBASECLASSCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::hicpp {
+namespace clang::tidy::bugprone {
/// Check for thrown exceptions and enforce they are all derived from
/// std::exception.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/hicpp/exception-baseclass.html
-class ExceptionBaseclassCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/std-exception-baseclass.html
+class StdExceptionBaseclassCheck : public ClangTidyCheck {
public:
- ExceptionBaseclassCheck(StringRef Name, ClangTidyContext *Context)
+ StdExceptionBaseclassCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
@@ -29,6 +29,6 @@ class ExceptionBaseclassCheck : public ClangTidyCheck {
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::hicpp
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_HICPP_EXCEPTIONBASECLASSCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STDEXCEPTIONBASECLASSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt b/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt
index 2f31d168e65c0..e3fc26d662132 100644
--- a/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/hicpp/CMakeLists.txt
@@ -4,7 +4,6 @@ set(LLVM_LINK_COMPONENTS
)
add_clang_library(clangTidyHICPPModule STATIC
- ExceptionBaseclassCheck.cpp
HICPPTidyModule.cpp
IgnoredRemoveResultCheck.cpp
MultiwayPathsCoveredCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
index 2e0e64fbcd2a1..f9aa4a233a399 100644
--- a/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
@@ -8,6 +8,7 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
+#include "../bugprone/StdExceptionBaseclassCheck.h"
#include "../bugprone/UndelegatedConstructorCheck.h"
#include "../bugprone/UseAfterMoveCheck.h"
#include "../cppcoreguidelines/AvoidGotoCheck.h"
@@ -34,7 +35,6 @@
#include "../readability/FunctionSizeCheck.h"
#include "../readability/NamedParameterCheck.h"
#include "../readability/UppercaseLiteralSuffixCheck.h"
-#include "ExceptionBaseclassCheck.h"
#include "IgnoredRemoveResultCheck.h"
#include "MultiwayPathsCoveredCheck.h"
#include "NoAssemblerCheck.h"
@@ -55,7 +55,7 @@ class HICPPModule : public ClangTidyModule {
"hicpp-braces-around-statements");
CheckFactories.registerCheck<modernize::DeprecatedHeadersCheck>(
"hicpp-deprecated-headers");
- CheckFactories.registerCheck<ExceptionBaseclassCheck>(
+ CheckFactories.registerCheck<bugprone::StdExceptionBaseclassCheck>(
"hicpp-exception-baseclass");
CheckFactories.registerCheck<IgnoredRemoveResultCheck>(
"hicpp-ignored-remove-result");
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/std-exception-baseclass.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/std-exception-baseclass.rst
new file mode 100644
index 0000000000000..68d13169ebeb5
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/std-exception-baseclass.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - bugprone-std-exception-baseclass
+
+bugprone-std-exception-baseclass
+================================
+
+Ensure that every value that in a ``throw`` expression is an instance of
+``std::exception``.
+
+.. code-block:: c++
+
+ class custom_exception {};
+
+ void throwing() noexcept(false) {
+ // Problematic throw expressions.
+ throw int(42);
+ throw custom_exception();
+ }
+
+ class mathematical_error : public std::exception {};
+
+ void throwing2() noexcept(false) {
+ // These kind of throws are ok.
+ throw mathematical_error();
+ throw std::runtime_error();
+ throw std::exception();
+ }
diff --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/exception-baseclass.rst b/clang-tools-extra/docs/clang-tidy/checks/hicpp/exception-baseclass.rst
index 7a1c1a07c49e3..df92f8407d5d7 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/exception-baseclass.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/exception-baseclass.rst
@@ -1,29 +1,10 @@
.. title:: clang-tidy - hicpp-exception-baseclass
+.. meta::
+ :http-equiv=refresh: 5;URL=../bugprone/std-exception-baseclass.html
hicpp-exception-baseclass
=========================
-Ensure that every value that in a ``throw`` expression is an instance of
-``std::exception``.
-
-This enforces `rule 15.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-rules>`_
-of the High Integrity C++ Coding Standard.
-
-.. code-block:: c++
-
- class custom_exception {};
-
- void throwing() noexcept(false) {
- // Problematic throw expressions.
- throw int(42);
- throw custom_exception();
- }
-
- class mathematical_error : public std::exception {};
-
- void throwing2() noexcept(false) {
- // These kind of throws are ok.
- throw mathematical_error();
- throw std::runtime_error();
- throw std::exception();
- }
+The `hicpp-exception-baseclass` check is an alias, please see
+`bugprone-std-exception-baseclass <../bugprone/std-exception-baseclass.html>`_
+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..4377284db50bf 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -146,6 +146,7 @@ Clang-Tidy Checks
:doc:`bugprone-sizeof-expression <bugprone/sizeof-expression>`,
:doc:`bugprone-spuriously-wake-up-functions <bugprone/spuriously-wake-up-functions>`,
:doc:`bugprone-standalone-empty <bugprone/standalone-empty>`, "Yes"
+ :doc:`bugprone-std-exception-baseclass <bugprone/std-exception-baseclass>`,
:doc:`bugprone-std-namespace-modification <bugprone/std-namespace-modification>`,
:doc:`bugprone-string-constructor <bugprone/string-constructor>`, "Yes"
:doc:`bugprone-string-integer-assignment <bugprone/string-integer-assignment>`, "Yes"
@@ -240,7 +241,6 @@ Clang-Tidy Checks
:doc:`google-runtime-int <google/runtime-int>`,
: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>`,
@@ -599,6 +599,7 @@ Check aliases
:doc:`hicpp-avoid-goto <hicpp/avoid-goto>`, :doc:`cppcoreguidelines-avoid-goto <cppcoreguidelines/avoid-goto>`,
:doc:`hicpp-braces-around-statements <hicpp/braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
:doc:`hicpp-deprecated-headers <hicpp/deprecated-headers>`, :doc:`modernize-deprecated-headers <modernize/deprecated-headers>`, "Yes"
+ :doc:`hicpp-exception-baseclass <hicpp/exception-baseclass>`, :doc:`bugprone-std-exception-baseclass <bugprone/std-exception-baseclass>`,
: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-invalid-access-moved <hicpp/invalid-access-moved>`, :doc:`bugprone-use-after-move <bugprone/use-after-move>`,
diff --git a/clang-tools-extra/test/clang-tidy/checkers/hicpp/exception-baseclass.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/std-exception-baseclass.cpp
similarity index 99%
rename from clang-tools-extra/test/clang-tidy/checkers/hicpp/exception-baseclass.cpp
rename to clang-tools-extra/test/clang-tidy/checkers/bugprone/std-exception-baseclass.cpp
index b5e405a691848..56a85f282c0e7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/hicpp/exception-baseclass.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/std-exception-baseclass.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s hicpp-exception-baseclass %t -- -- -fcxx-exceptions
+// RUN: %check_clang_tidy %s bugprone-std-exception-baseclass %t -- -- -fcxx-exceptions
namespace std {
class exception {};
``````````
</details>
https://github.com/llvm/llvm-project/pull/183474
More information about the cfe-commits
mailing list