[clang-tools-extra] [clang-tidy] Fixes to readability-implicit-bool-conversion (PR #72050)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 15 21:57:36 PST 2024


================
@@ -173,16 +173,30 @@ StringRef getEquivalentBoolLiteralForExpr(const Expr *Expression,
   return {};
 }
 
+bool needsSpacePrefix(SourceLocation Loc, ASTContext &Context) {
+  SourceRange PrefixRange(Loc.getLocWithOffset(-1), Loc);
+  StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
+      CharSourceRange::getCharRange(PrefixRange), Context.getSourceManager(),
+      Context.getLangOpts(), nullptr);
+  if (SpaceBeforeStmtStr.empty())
+    return true;
+
+  const StringRef AllowedCharacters(" \t\n\v\f\r(){}[]<>;,+=-|&~!^*/");
+  return SpaceBeforeStmtStr.rtrim(AllowedCharacters).size() ==
----------------
HerrCai0907 wrote:

use `SpaceBeforeStmtStr.back()` and `SpaceBeforeStmtStr.front()`

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


More information about the cfe-commits mailing list