[clang-tools-extra] [clang-tidy] Add modernize-avoid-fundamental-integer-types (PR #146970)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 3 16:03:33 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.cpp clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.h clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-fundamental-integer-types.cpp clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.cpp
index b5e2484e6..a74e31162 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.cpp
@@ -86,33 +86,21 @@ bool AvoidFundamentalIntegerTypesCheck::isSemanticType(const Type *T) const {
void AvoidFundamentalIntegerTypesCheck::registerMatchers(MatchFinder *Finder) {
// Match variable declarations with fundamental integer types
- Finder->addMatcher(
- varDecl().bind("var_decl"),
- this);
+ Finder->addMatcher(varDecl().bind("var_decl"), this);
// Match function declarations with fundamental integer return types
- Finder->addMatcher(
- functionDecl().bind("func_decl"),
- this);
+ Finder->addMatcher(functionDecl().bind("func_decl"), this);
// Match function parameters with fundamental integer types
- Finder->addMatcher(
- parmVarDecl().bind("param_decl"),
- this);
+ Finder->addMatcher(parmVarDecl().bind("param_decl"), this);
// Match field declarations with fundamental integer types
- Finder->addMatcher(
- fieldDecl().bind("field_decl"),
- this);
+ Finder->addMatcher(fieldDecl().bind("field_decl"), this);
// Match typedef declarations to check their underlying types
- Finder->addMatcher(
- typedefDecl().bind("typedef_decl"),
- this);
+ Finder->addMatcher(typedefDecl().bind("typedef_decl"), this);
- Finder->addMatcher(
- typeAliasDecl().bind("alias_decl"),
- this);
+ Finder->addMatcher(typeAliasDecl().bind("alias_decl"), this);
}
void AvoidFundamentalIntegerTypesCheck::check(
@@ -125,11 +113,13 @@ void AvoidFundamentalIntegerTypesCheck::check(
Loc = VD->getLocation();
QT = VD->getType();
DeclType = "variable";
- } else if (const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("func_decl")) {
+ } else if (const auto *FD =
+ Result.Nodes.getNodeAs<FunctionDecl>("func_decl")) {
Loc = FD->getLocation();
QT = FD->getReturnType();
DeclType = "function return type";
- } else if (const auto *PD = Result.Nodes.getNodeAs<ParmVarDecl>("param_decl")) {
+ } else if (const auto *PD =
+ Result.Nodes.getNodeAs<ParmVarDecl>("param_decl")) {
Loc = PD->getLocation();
QT = PD->getType();
DeclType = "function parameter";
@@ -137,11 +127,13 @@ void AvoidFundamentalIntegerTypesCheck::check(
Loc = FD->getLocation();
QT = FD->getType();
DeclType = "field";
- } else if (const auto *TD = Result.Nodes.getNodeAs<TypedefDecl>("typedef_decl")) {
+ } else if (const auto *TD =
+ Result.Nodes.getNodeAs<TypedefDecl>("typedef_decl")) {
Loc = TD->getLocation();
QT = TD->getUnderlyingType();
DeclType = "typedef";
- } else if (const auto *AD = Result.Nodes.getNodeAs<TypeAliasDecl>("alias_decl")) {
+ } else if (const auto *AD =
+ Result.Nodes.getNodeAs<TypeAliasDecl>("alias_decl")) {
Loc = AD->getLocation();
QT = AD->getUnderlyingType();
DeclType = "type alias";
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.h b/clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.h
index c1e4fb474..555a6c9e7 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidFundamentalIntegerTypesCheck.h
@@ -13,7 +13,8 @@
namespace clang::tidy::modernize {
-/// Find fundamental integer types and recommend using typedefs or fixed-width types.
+/// Find fundamental integer types and recommend using typedefs or fixed-width
+/// types.
///
/// Detects fundamental integer types (int, short, long, long long, and their
/// unsigned variants) and warns against their use due to platform-dependent
``````````
</details>
https://github.com/llvm/llvm-project/pull/146970
More information about the cfe-commits
mailing list