Skip to content

Conversation

@flovent
Copy link
Contributor

@flovent flovent commented Sep 8, 2025

Closes #156154

@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: None (flovent)

Changes

Closes #156154


Full diff: https://github.com/llvm/llvm-project/pull/157468.diff

4 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/.clang-tidy (-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp (+3-3)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp (+1-1)
diff --git a/clang-tools-extra/clang-tidy/.clang-tidy b/clang-tools-extra/clang-tidy/.clang-tidy
index 0e33364442e76..51e04876d655d 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -11,7 +11,6 @@ Checks: >
   modernize-*,
   -modernize-avoid-c-arrays,
   -modernize-pass-by-value,
-  -modernize-use-auto,
   -modernize-use-nodiscard,
   -modernize-use-trailing-return-type,
   performance-*,
diff --git a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index eeba5cce80da5..4726674be66fd 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -138,9 +138,9 @@ void UseIntegerSignComparisonCheck::check(
     return;
   const Expr *SubExprLHS = nullptr;
   const Expr *SubExprRHS = nullptr;
-  SourceRange R1 = SourceRange(LHS->getBeginLoc());
-  SourceRange R2 = SourceRange(BinaryOp->getOperatorLoc());
-  SourceRange R3 = SourceRange(Lexer::getLocForEndOfToken(
+  SourceRange R1(LHS->getBeginLoc());
+  SourceRange R2(BinaryOp->getOperatorLoc());
+  SourceRange R3(Lexer::getLocForEndOfToken(
       RHS->getEndLoc(), 0, *Result.SourceManager, getLangOpts()));
   if (const auto *LHSCast = llvm::dyn_cast<ExplicitCastExpr>(LHS)) {
     SubExprLHS = LHSCast->getSubExpr();
diff --git a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
index c74db0ed861b4..4041c81526d2f 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
@@ -98,7 +98,7 @@ static SourceRange getLockGuardRange(const TypeSourceInfo *SourceInfo) {
 
 // Find the exact source range of the 'lock_guard' name token
 static SourceRange getLockGuardNameRange(const TypeSourceInfo *SourceInfo) {
-  const TemplateSpecializationTypeLoc TemplateLoc =
+  const auto TemplateLoc =
       SourceInfo->getTypeLoc().getAs<TemplateSpecializationTypeLoc>();
   if (!TemplateLoc)
     return {};
diff --git a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
index 718467ed02f0a..511256332cee9 100644
--- a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
@@ -62,7 +62,7 @@ static bool maxCondition(const BinaryOperator::Opcode Op, const Expr *CondLhs,
 static QualType getNonTemplateAlias(QualType QT) {
   while (true) {
     // cast to a TypedefType
-    if (const TypedefType *TT = dyn_cast<TypedefType>(QT)) {
+    if (const auto *TT = dyn_cast<TypedefType>(QT)) {
       // check if the typedef is a template and if it is dependent
       if (!TT->getDecl()->getDescribedTemplate() &&
           !TT->getDecl()->getDeclContext()->isDependentContext())

@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-clang-tidy

Author: None (flovent)

Changes

Closes #156154


Full diff: https://github.com/llvm/llvm-project/pull/157468.diff

4 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/.clang-tidy (-1)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp (+3-3)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp (+1-1)
diff --git a/clang-tools-extra/clang-tidy/.clang-tidy b/clang-tools-extra/clang-tidy/.clang-tidy
index 0e33364442e76..51e04876d655d 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -11,7 +11,6 @@ Checks: >
   modernize-*,
   -modernize-avoid-c-arrays,
   -modernize-pass-by-value,
-  -modernize-use-auto,
   -modernize-use-nodiscard,
   -modernize-use-trailing-return-type,
   performance-*,
diff --git a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index eeba5cce80da5..4726674be66fd 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -138,9 +138,9 @@ void UseIntegerSignComparisonCheck::check(
     return;
   const Expr *SubExprLHS = nullptr;
   const Expr *SubExprRHS = nullptr;
-  SourceRange R1 = SourceRange(LHS->getBeginLoc());
-  SourceRange R2 = SourceRange(BinaryOp->getOperatorLoc());
-  SourceRange R3 = SourceRange(Lexer::getLocForEndOfToken(
+  SourceRange R1(LHS->getBeginLoc());
+  SourceRange R2(BinaryOp->getOperatorLoc());
+  SourceRange R3(Lexer::getLocForEndOfToken(
       RHS->getEndLoc(), 0, *Result.SourceManager, getLangOpts()));
   if (const auto *LHSCast = llvm::dyn_cast<ExplicitCastExpr>(LHS)) {
     SubExprLHS = LHSCast->getSubExpr();
diff --git a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
index c74db0ed861b4..4041c81526d2f 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
@@ -98,7 +98,7 @@ static SourceRange getLockGuardRange(const TypeSourceInfo *SourceInfo) {
 
 // Find the exact source range of the 'lock_guard' name token
 static SourceRange getLockGuardNameRange(const TypeSourceInfo *SourceInfo) {
-  const TemplateSpecializationTypeLoc TemplateLoc =
+  const auto TemplateLoc =
       SourceInfo->getTypeLoc().getAs<TemplateSpecializationTypeLoc>();
   if (!TemplateLoc)
     return {};
diff --git a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
index 718467ed02f0a..511256332cee9 100644
--- a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
@@ -62,7 +62,7 @@ static bool maxCondition(const BinaryOperator::Opcode Op, const Expr *CondLhs,
 static QualType getNonTemplateAlias(QualType QT) {
   while (true) {
     // cast to a TypedefType
-    if (const TypedefType *TT = dyn_cast<TypedefType>(QT)) {
+    if (const auto *TT = dyn_cast<TypedefType>(QT)) {
       // check if the typedef is a template and if it is dependent
       if (!TT->getDecl()->getDescribedTemplate() &&
           !TT->getDecl()->getDeclContext()->isDependentContext())

SourceRange R1 = SourceRange(LHS->getBeginLoc());
SourceRange R2 = SourceRange(BinaryOp->getOperatorLoc());
SourceRange R3 = SourceRange(Lexer::getLocForEndOfToken(
SourceRange R1(LHS->getBeginLoc());
Copy link
Contributor Author

@flovent flovent Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check correctly suggest auto R1 = SourceRange(LHS->getBeginLoc()); here, but i think directly calling ctor is better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

Copy link
Contributor

@vbvictor vbvictor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you

@vbvictor vbvictor merged commit 3b452e0 into llvm:main Sep 8, 2025
12 checks passed
@flovent flovent deleted the tidy-enable-modernize-use-auto branch September 9, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clang-tidy] Enable 'modernize-use-auto' check in clang-tidy config.

3 participants