[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 1 10:23:12 PST 2018

aaron.ballman added inline comments.

Comment at: clang-tidy/bugprone/UnusedReturnValueCheck.cpp:62-63
+void UnusedReturnValueCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto Matched = Result.Nodes.getNodeAs<Stmt>("match")) {
+    diag(Matched->getLocStart(), "unused return value");
+  }
`const auto Matched` -> `const auto *Matched`

You can elide the curly braces.

The diagnostic doesn't really help the user understand what's wrong with the code. How about "the value returned by this function should be used" and add a note diagnostic that says "cast expression to void to silence warning". Also, you should pass in the `SourceRange` for the function call expression to the call to `diag()` so that it highlights the call in question.

Comment at: test/clang-tidy/bugprone-unused-return-value.cpp:200
+  increment(1);
Can you also add a test for ignoring the result of a call to `std::empty(SomeContainerWithAnEmptyMethod)`?


More information about the cfe-commits mailing list