[clang-tools-extra] [clang-tidy][NFC] replace comparison of begin and end iterators with range empty (PR #91994)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 13 09:51:36 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
Author: Julian Schmidt (5chmidti)
<details>
<summary>Changes</summary>
Improves readability by changing comparisons of `*begin` and `*end`
iterators into `.empty()` on their range.
---
Full diff: https://github.com/llvm/llvm-project/pull/91994.diff
4 Files Affected:
- (modified) clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp (+1-2)
- (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp (+1-2)
- (modified) clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp (+1-3)
- (modified) clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp (+1-1)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
index ca1ae551cc632..2fca7ae2e7eee 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
@@ -171,8 +171,7 @@ void SuspiciousEnumUsageCheck::check(const MatchFinder::MatchResult &Result) {
// Skip when one of the parameters is an empty enum. The
// hasDisjointValueRange function could not decide the values properly in
// case of an empty enum.
- if (EnumDec->enumerator_begin() == EnumDec->enumerator_end() ||
- OtherEnumDec->enumerator_begin() == OtherEnumDec->enumerator_end())
+ if (EnumDec->enumerators().empty() || OtherEnumDec->enumerators().empty())
return;
if (!hasDisjointValueRange(EnumDec, OtherEnumDec))
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
index 00dfa17a1ccf6..5dee7f91a9341 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
@@ -67,8 +67,7 @@ static std::string createReplacementText(const LambdaExpr *Lambda) {
AppendName("this");
}
}
- if (!Replacement.empty() &&
- Lambda->explicit_capture_begin() != Lambda->explicit_capture_end()) {
+ if (!Replacement.empty() && !Lambda->explicit_captures().empty()) {
// Add back separator if we are adding explicit capture variables.
Stream << ", ";
}
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
index 3f1d2f9f58099..c2d9286312dc4 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
@@ -192,9 +192,7 @@ void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) {
// In non-strict mode ignore function definitions with empty bodies
// (constructor initializer counts for non-empty body).
- if (StrictMode ||
- (Function->getBody()->child_begin() !=
- Function->getBody()->child_end()) ||
+ if (StrictMode || !Function->getBody()->children().empty() ||
(isa<CXXConstructorDecl>(Function) &&
cast<CXXConstructorDecl>(Function)->getNumCtorInitializers() > 0))
warnOnUnusedParameter(Result, Function, I);
diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
index 6d7d1d6b87c60..1585925ee9967 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
@@ -254,7 +254,7 @@ findInsertionForConstraint(const FunctionDecl *Function, ASTContext &Context) {
return utils::lexer::findPreviousTokenKind(Init->getSourceLocation(),
SM, LangOpts, tok::colon);
}
- if (Constructor->init_begin() != Constructor->init_end())
+ if (!Constructor->inits().empty())
return std::nullopt;
}
if (Function->isDeleted()) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/91994
More information about the cfe-commits
mailing list