mirror-llvm-project/clang-tools-extra/clang-tidy
hehuan 60f965b1f6
[clang-tidy] Fix trailing semicolon and lost comment in readability-use-std-min-max (#208782)
Fix two bugs in readability-use-std-min-max when the if body has no
braces.

For brace-less if bodies, If->getEndLoc() points to the expression end
rather than the trailing semicolon, truncating replacements and losing
comments. We find the semicolon via findNextToken and extend the range
consistent with compound statement logic.

Before:
  if (n < -1) n = -1 ;          ->  n = std::max(n, -1); ;
  if (n > 1) n = 1/*comment*/;  ->  n = std::min(n, 1);;

After:
  if (n < -1) n = -1 ;          ->  n = std::max(n, -1);
  if (n > 1) n = 1/*comment*/;  ->  n = std::min(n, 1); /*comment*/

Fixes #208708.

AI Usage: This patch is AI-assisted, reviewed and verified by me.
2026-08-01 19:09:50 +08:00
..
abseil [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
altera [clang][AST] Refactor EvaluatedStmt accessors in VarDecl (#205033) 2026-06-24 05:29:28 +02:00
android [clang-tidy][NFC] Fix incorrect list.rst modification by add_new_check.py (#179297) 2026-02-03 08:11:34 +08:00
boost [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
bugprone [clang-tidy] Move part of bugprone-unhandled-code-paths to a new check readability-trivial-switch (#198237) 2026-06-28 14:50:57 +00:00
cert [clang-tidy] Fix cert-err33-c inheriting CheckedReturnTypes from bugp… (#200169) 2026-06-01 21:12:02 +02:00
concurrency [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
cppcoreguidelines [clang-tidy] Add AllowImplicitMove option to rvalue-reference-param-not-moved (#190541) 2026-07-09 08:13:24 +03:00
custom [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
darwin [clang-tidy] Merge ClangTidyModuleRegistry.h into ClangTidyModule.h (#173231) 2025-12-23 15:06:47 -06:00
fuchsia [clang-tidy] Avoid evaluating value-dependent static initializers in fuchsia-statically-constructed-objects (#201287) 2026-06-03 17:51:30 +08:00
google [clang-tidy] Migrate explicit-constructor check from google to misc and add relative aliases (#194807) 2026-05-09 13:32:48 +03:00
linuxkernel [clang-tidy] Merge ClangTidyModuleRegistry.h into ClangTidyModule.h (#173231) 2025-12-23 15:06:47 -06:00
llvm [clang-tidy] detect uses of llvm::isa that are always true (#191081) 2026-05-20 23:44:32 -07:00
llvmlibc [clang-tidy][NFC] Apply const-correctness to code (#203823) 2026-06-15 08:45:14 +03:00
misc [clang-tidy] Fix nested macro false positives in misc-redundant-expression (#209385) 2026-07-26 12:37:48 +00:00
modernize [clang-tidy] Flag consecutive scoped_locks in use-scoped-lock (#209272) 2026-07-14 10:39:24 +03:00
mpi [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
objc [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
openmp [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
performance [clang-tidy] Add performance-expensive-value-or check (#200166) 2026-07-24 00:33:39 +02:00
plugin [clang-tidy][NFC] Give structs, classes, and enums internal linkage where applicable (#172947) 2025-12-19 16:44:30 +00:00
portability [clang-tidy][NFC] Remove another ad-hoc exclusion for system headers (#190094) 2026-04-02 20:52:47 +00:00
readability [clang-tidy] Fix trailing semicolon and lost comment in readability-use-std-min-max (#208782) 2026-08-01 19:09:50 +08:00
tool [clang-tidy] Run analysis even with no checks (as long as --allow-no-checks is passed) (#194006) 2026-05-12 12:59:00 +00:00
utils [clang-tidy] Move isStdInitializerList to utils::type_traits and add unit tests (#205449) 2026-06-25 09:06:22 -07:00
zircon [clang-tidy] Merge ClangTidyModuleRegistry.h into ClangTidyModule.h (#173231) 2025-12-23 15:06:47 -06:00
.clang-format [clang-tidy][NFC] Enable RemoveSemicolon in clang-format config (#176926) 2026-01-21 12:10:03 +03:00
.clang-tidy [clang-tidy][NFC] add config for 22.x clang-tidy (#184834) 2026-03-06 12:38:53 +03:00
add_new_check.py [clang-tidy] Generate Markdown documentation for new checks (#210574) 2026-07-23 01:02:54 +00:00
clang-tidy-config.h.cmake reapply "[clang-tidy] support query based custom check" (#159547) 2025-09-19 21:47:57 +08:00
ClangTidy.cpp [Clang] Refactor and consolidate color diagnostic handling (#202441) 2026-06-29 15:30:10 -05:00
ClangTidy.h [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
ClangTidyCheck.cpp [clang-tidy][NFC] Apply const-correctness to code (#203823) 2026-06-15 08:45:14 +03:00
ClangTidyCheck.h [clang-tidy][NFC] Don't store a redundant copy of HeaderFileExtensions in every check (#190302) 2026-04-07 20:08:22 -07:00
ClangTidyDiagnosticConsumer.cpp [clang-tidy][clang][diagnostics] Unify system header/macro supression (#193774) 2026-05-11 18:50:37 +02:00
ClangTidyDiagnosticConsumer.h [clang-tidy][clang][diagnostics] Unify system header/macro supression (#193774) 2026-05-11 18:50:37 +02:00
ClangTidyForceLinker.h [clang-tidy] Remove hicpp module [5/5] (#197384) 2026-05-15 01:21:03 +08:00
ClangTidyModule.cpp [clang-tidy][NFC] Remove redundant braces with clang-format 'RemoveBracesLLVM' (1/N) (#172748) 2025-12-18 14:58:21 +03:00
ClangTidyModule.h [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
ClangTidyModuleRegistry.h [clang-tidy] Merge ClangTidyModuleRegistry.h into ClangTidyModule.h (#173231) 2025-12-23 15:06:47 -06:00
ClangTidyOptions.cpp [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
ClangTidyOptions.h [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
ClangTidyProfiling.cpp [clang-tidy] Generate valid JSON for characters that require escaping (#187454) 2026-03-20 23:55:00 +08:00
ClangTidyProfiling.h [clang-tidy][NFC] Switch to new file header style (#158497) 2025-09-14 14:06:20 -06:00
CMakeLists.txt [clang-tidy] Remove hicpp module [5/5] (#197384) 2026-05-15 01:21:03 +08:00
doc8.ini [clang-tidy] Remove 80 char limit checking in CI. NFC. (#197609) 2026-05-14 12:32:14 +08:00
ExpandModularHeadersPPCallbacks.cpp [clang][modules] Remove Module::ASTFile (#185994) 2026-03-19 13:06:49 -07:00
ExpandModularHeadersPPCallbacks.h [clang-tidy][NFC] Switch to new file header style: attempt number two (#172451) 2025-12-16 03:27:41 -08:00
FileExtensionsSet.h [clang-tidy][NFC] Update header guards to match LLVM style (#166669) 2025-11-07 23:23:50 +03:00
GlobList.cpp [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
GlobList.h [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
NoLintDirectiveHandler.cpp [clang-tidy][NFC] Fix readability-inconsistent-ifelse-braces warnings (#182764) 2026-02-23 11:17:58 +03:00
NoLintDirectiveHandler.h [clang-tidy][NFC] Don't qualify names unless strictly necessary (#185169) 2026-03-11 06:40:25 -07:00
rename_check.py [clang-tidy] Support Markdown documentation in rename_check.py (#210577) 2026-07-26 20:51:23 +08:00