================ @@ -130,26 +130,35 @@ UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name, "::std::error_condition;" "::std::errc;" "::std::expected;" - "::boost::system::error_code"))) {} + "::boost::system::error_code"))), + AllowCastToVoid(Options.get("AllowCastToVoid", false)) {} void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "CheckedFunctions", CheckedFunctions); Options.store(Opts, "CheckedReturnTypes", utils::options::serializeStringList(CheckedReturnTypes)); + Options.store(Opts, "AllowCastToVoid", AllowCastToVoid); } void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) { auto FunVec = utils::options::parseStringList(CheckedFunctions); - auto MatchedCallExpr = expr(ignoringImplicit(ignoringParenImpCasts( - callExpr(callee(functionDecl( - // Don't match void overloads of checked functions. - unless(returns(voidType())), - anyOf(isInstantiatedFrom(hasAnyName(FunVec)), - returns(hasCanonicalType(hasDeclaration( - namedDecl(matchers::matchesAnyListedName( - CheckedReturnTypes))))))))) - .bind("match")))); + auto MatchedDirectCallExpr = + expr(callExpr(callee(functionDecl( + // Don't match void overloads of checked functions. + unless(returns(voidType())), + anyOf(isInstantiatedFrom(hasAnyName(FunVec)), + returns(hasCanonicalType(hasDeclaration( + namedDecl(matchers::matchesAnyListedName( + CheckedReturnTypes))))))))) + .bind("match")); + + auto CheckCastToVoid = + AllowCastToVoid ? castExpr(unless(hasCastKind(CK_ToVoid))) : castExpr(); + auto MatchedCallExpr = expr( + anyOf(MatchedDirectCallExpr, + explicitCastExpr(unless(cxxFunctionalCastExpr()), CheckCastToVoid, ---------------- PiotrZSL wrote:
It actually does the same.. explicitCastExpr inherit from castExpr, so you can use parent matcher also. https://github.com/llvm/llvm-project/pull/66573 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits