[PATCH] D153860: [clang-tidy] Fix modernize-use-std-print check when return value used

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 27 07:59:05 PDT 2023


PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:73-95
+static clang::ast_matchers::StatementMatcher
+unusedReturnValue(clang::ast_matchers::StatementMatcher MatchedCallExpr) {
+  auto UnusedInCompoundStmt =
+      compoundStmt(forEach(MatchedCallExpr),
+                   // The checker can't currently differentiate between the
+                   // return statement and other statements inside GNU statement
+                   // expressions, so disable the checker inside them to avoid
----------------
NOTE: Personally I do not thing that this is right way. Instead of using "inclusion" matcher, better would be to use elimination.
like:
```callExpr(unless(hasParent(anyOf(varDecl(), callExpr(), ifStmt(), ...```.

But if it's working fine, then it could be for now, so lets leave it. Simply with this it may not find all cases.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp:63
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:10: warning: use 'std::println' instead of 'PrintF' [modernize-use-std-print]
+  // CHECK-FIXES-NOT: std::println("return value {}", i);
+}
----------------
NOTE: I don't think that those FIXES-NOT are needed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153860/new/

https://reviews.llvm.org/D153860



More information about the cfe-commits mailing list