chaitanyav updated this revision to Diff 525359. chaitanyav added a comment.
Reuse diag code Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151383/new/ https://reviews.llvm.org/D151383 Files: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp @@ -156,6 +156,15 @@ auto UnusedInRangeForStmt = cxxForRangeStmt(hasBody(MatchedCallExpr)); auto UnusedInCaseStmt = switchCase(forEach(MatchedCallExpr)); + Finder->addMatcher( + callExpr(callee(functionDecl(anyOf( + hasReturnTypeLoc(loc(asString("std::error_code"))), + hasReturnTypeLoc(loc(asString("std::expected"))), + hasReturnTypeLoc(loc(asString("boost::system::error_code"))), + hasReturnTypeLoc(loc(asString("abseil::Status"))))))) + .bind("return-types"), + this); + Finder->addMatcher( stmt(anyOf(UnusedInCompoundStmt, UnusedInIfStmt, UnusedInWhileStmt, UnusedInDoStmt, UnusedInForStmt, UnusedInRangeForStmt, @@ -164,13 +173,17 @@ } void UnusedReturnValueCheck::check(const MatchFinder::MatchResult &Result) { - if (const auto *Matched = Result.Nodes.getNodeAs<CallExpr>("match")) { - diag(Matched->getBeginLoc(), - "the value returned by this function should be used") - << Matched->getSourceRange(); - diag(Matched->getBeginLoc(), - "cast the expression to void to silence this warning", - DiagnosticIDs::Note); + const char *callExprBindingNames[] = {"return-types", "match"}; + for (const char *callExprBindingName : callExprBindingNames) { + if (const auto *Matched = + Result.Nodes.getNodeAs<CallExpr>(callExprBindingName)) { + diag(Matched->getBeginLoc(), + "the value returned by this function should be used") + << Matched->getSourceRange(); + diag(Matched->getBeginLoc(), + "cast the expression to void to silence this warning", + DiagnosticIDs::Note); + }; } }
Index: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp +++ clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp @@ -156,6 +156,15 @@ auto UnusedInRangeForStmt = cxxForRangeStmt(hasBody(MatchedCallExpr)); auto UnusedInCaseStmt = switchCase(forEach(MatchedCallExpr)); + Finder->addMatcher( + callExpr(callee(functionDecl(anyOf( + hasReturnTypeLoc(loc(asString("std::error_code"))), + hasReturnTypeLoc(loc(asString("std::expected"))), + hasReturnTypeLoc(loc(asString("boost::system::error_code"))), + hasReturnTypeLoc(loc(asString("abseil::Status"))))))) + .bind("return-types"), + this); + Finder->addMatcher( stmt(anyOf(UnusedInCompoundStmt, UnusedInIfStmt, UnusedInWhileStmt, UnusedInDoStmt, UnusedInForStmt, UnusedInRangeForStmt, @@ -164,13 +173,17 @@ } void UnusedReturnValueCheck::check(const MatchFinder::MatchResult &Result) { - if (const auto *Matched = Result.Nodes.getNodeAs<CallExpr>("match")) { - diag(Matched->getBeginLoc(), - "the value returned by this function should be used") - << Matched->getSourceRange(); - diag(Matched->getBeginLoc(), - "cast the expression to void to silence this warning", - DiagnosticIDs::Note); + const char *callExprBindingNames[] = {"return-types", "match"}; + for (const char *callExprBindingName : callExprBindingNames) { + if (const auto *Matched = + Result.Nodes.getNodeAs<CallExpr>(callExprBindingName)) { + diag(Matched->getBeginLoc(), + "the value returned by this function should be used") + << Matched->getSourceRange(); + diag(Matched->getBeginLoc(), + "cast the expression to void to silence this warning", + DiagnosticIDs::Note); + }; } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits