-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang-tidy][NFC] Enable modernize-use-auto in clang-tidy config and fix warnings
#157468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-clang-tools-extra Author: None (flovent) ChangesCloses #156154 Full diff: https://github.com/llvm/llvm-project/pull/157468.diff 4 Files Affected:
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())
|
|
@llvm/pr-subscribers-clang-tidy Author: None (flovent) ChangesCloses #156154 Full diff: https://github.com/llvm/llvm-project/pull/157468.diff 4 Files Affected:
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
vbvictor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you
Closes #156154