================
@@ -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(
+ CharSourceRange::getCharRange(
+ Lexer::getLocForEndOfToken(If->getRParenLoc(), 0, Source, LO),
+ If->getThen()->getBeginLoc()),
+ Source, LO));
+
+ if (const auto *CS = dyn_cast<CompoundStmt>(If->getThen())) {
+ const Stmt *Inner = CS->body_front();
+ AppendNormalized(Lexer::getSourceText(
+ CharSourceRange::getCharRange(
+ Lexer::getLocForEndOfToken(CS->getBeginLoc(), 0, Source, LO),
+ Inner->getBeginLoc()),
+ Source, LO));
+
+ llvm::StringRef PostInner = Lexer::getSourceText(
----------------
zeyi2 wrote:
Captures:
- `if (cond) { x = y; // Comment C`
- `if (cond) { x = y; /* Comment C */ }`
It also strip the trailing `;`
https://github.com/llvm/llvm-project/pull/169908
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits