[clang-tools-extra] [clang-tidy][bugprone-posix-return] support integer literals as LHS (PR #109302)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 26 16:24:36 PDT 2024


================
@@ -61,23 +67,26 @@ void PosixReturnCheck::check(const MatchFinder::MatchResult &Result) {
   if (const auto *LessThanZeroOp =
           Result.Nodes.getNodeAs<BinaryOperator>("ltzop")) {
     SourceLocation OperatorLoc = LessThanZeroOp->getOperatorLoc();
+    const char NewBinOp =
+        LessThanZeroOp->getOpcode() == BinaryOperator::Opcode::BO_LT ? '>'
+                                                                     : '<';
     diag(OperatorLoc, "the comparison always evaluates to false because %0 "
                       "always returns non-negative values")
-        << getFunctionSpelling(Result, "ltzop")
-        << FixItHint::CreateReplacement(OperatorLoc, Twine(">").str());
+        << getFunctionSpelling(Result)
+        << FixItHint::CreateReplacement(OperatorLoc, Twine(NewBinOp).str());
----------------
5chmidti wrote:

Nit: the `Twine` isn't needed, `CreateReplacement` takes a `StringRef`

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


More information about the cfe-commits mailing list