[clang-tools-extra] [clang-tidy] Preserve comments in `readability-use-std-min-max` (PR #169908)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 2 23:31:56 PST 2025
================
@@ -172,13 +172,52 @@ void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
auto ReplaceAndDiagnose = [&](const llvm::StringRef FunctionName) {
const SourceManager &Source = *Result.SourceManager;
+ llvm::SmallString<64> Comment;
+
+ const auto AppendNormalized = [&](llvm::StringRef Text) {
+ Text = Text.ltrim();
+ if (!Text.empty()) {
+ if (!Comment.empty())
+ Comment += " ";
+ Comment += Text;
+ }
+ };
+
+ AppendNormalized(Lexer::getSourceText(
----------------
zeyi2 wrote:
This part captures:
- `if (cond) // Comment A`
- `if (cond) /* Comment A */ { ... }`
- `if (cond) /* Comment A */ x = y;`
https://github.com/llvm/llvm-project/pull/169908
More information about the cfe-commits
mailing list