[clang-tools-extra] [clang-tidy] Fix trailing semicolon and lost comment in readability-use-std-min-max (PR #208782)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 31 07:14:46 PDT 2026


================
@@ -218,6 +218,18 @@ void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
       if (Semi != StringRef::npos && PostInner.take_front(Semi).trim().empty())
         PostInner = PostInner.drop_front(Semi + 1);
       AppendNormalized(PostInner);
+    } else {
+      // Non-compound case: find the trailing semicolon after the expression
+      // and capture any comments between the expression end and the
+      // semicolon.
+      std::optional<Token> SemiTok = Lexer::findNextToken(
----------------
zeyi2 wrote:

Nit: `findNextToken` already calls `getLocForEndOfToken` inside, so we can simplify this to:

```cpp
if (const auto SemiTok =
        Lexer::findNextToken(ThenLocation, Source, LO);
    SemiTok && SemiTok->is(tok::semi)) {
  AppendNormalized(
      GetSourceText(ThenLocation, SemiTok->getLocation()).rtrim());
  ThenLocation = SemiTok->getLocation();
}
```

Also, please remove the verbose comments.

```diff
-      // Non-compound case: find the trailing semicolon after the expression
-      // and capture any comments between the expression end and the
-      // semicolon.
```

https://github.com/llvm/llvm-project/pull/208782


More information about the cfe-commits mailing list