Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ void UseIntegerSignComparisonCheck::check(
if (const auto *RHSCast = llvm::dyn_cast<ExplicitCastExpr>(RHS)) {
SubExprRHS = RHSCast->getSubExpr();
R2.setEnd(SubExprRHS->getBeginLoc().getLocWithOffset(-1));
R3.setBegin(Lexer::getLocForEndOfToken(
SubExprRHS->getEndLoc(), 0, *Result.SourceManager, getLangOpts()));
Copy link
Contributor Author

@localspook localspook Oct 15, 2025

Choose a reason for hiding this comment

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

Notice how (before this change) this if statement and the one before it were asymmetric: the previous one correctly adjusted two ranges (R1 and R2), while this one incorrectly adjusted only one (R2).

Copy link
Contributor

Choose a reason for hiding this comment

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

Wish we had meaningful names for R1, R2, R3. Could be a later NFC patch

}
DiagnosticBuilder Diag =
diag(BinaryOp->getBeginLoc(),
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ Changes in existing checks
<clang-tidy/checks/modernize/use-designated-initializers>` check to
suggest using designated initializers for aliased aggregate types.

- Improved :doc:`modernize-use-integer-sign-comparison
<clang-tidy/checks/modernize/use-integer-sign-comparison>` by providing
correct fix-its when the right-hand side of a comparison contains a
non-C-style cast.

- Improved :doc:`modernize-use-nullptr
<clang-tidy/checks/modernize/use-nullptr>` check by fixing a crash
on Windows when the check was enabled with a 32-bit :program:`clang-tidy`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ int AllComparisons() {
if (static_cast<unsigned int>(uArray[2]) < static_cast<int>(sArray[2]))
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_less(uArray[2],sArray[2])))
// FIXME: There should only be 2 closing braces. The fix-it inserts an unbalanced one.
// CHECK-FIXES: if (q20::cmp_less(uArray[2],sArray[2]))

if ((unsigned int)uArray[3] < (int)sArray[3])
return 0;
Expand All @@ -116,6 +115,11 @@ int AllComparisons() {
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_greater(uArray[6] , VALUE))

if (unsigned(uArray[7]) >= int(sArray[7]))
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (q20::cmp_greater_equal(uArray[7],sArray[7]))


FuncParameters(uVar);
TemplateFuncParameter(sVar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ int AllComparisons() {
if (static_cast<unsigned int>(uArray[2]) < static_cast<int>(sArray[2]))
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (std::cmp_less(uArray[2],sArray[2])))
// FIXME: There should only be 2 closing braces. The fix-it inserts an unbalanced one.
// CHECK-FIXES: if (std::cmp_less(uArray[2],sArray[2]))

if ((unsigned int)uArray[3] < (int)sArray[3])
return 0;
Expand All @@ -115,6 +114,11 @@ int AllComparisons() {
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (std::cmp_greater(uArray[6] , VALUE))

if (unsigned(uArray[7]) >= int(sArray[7]))
return 0;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
// CHECK-FIXES: if (std::cmp_greater_equal(uArray[7],sArray[7]))


FuncParameters(uVar);
TemplateFuncParameter(sVar);
Expand Down