From 1061875d6747f3cb89466aa6df568620a7ddfa05 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 26 Oct 2017 21:04:40 +0200 Subject: Make loplugin:implicitboolconversion find the same in C++17 and pre-C++17 ...see a2d814ac1d7beb6fbe4b9cb7b75814f4b08b8e59 "loplugin:implicitboolconversion" and 24eeb4d286471e4a2103c15efc624a565112ca32 "loplugin:implicitboolconversion" for things previously only found in C++17. As expected, no further occurrences were found. Change-Id: Id0ab621b82dc3c40c8b5801413fceb73ade1408a --- compilerplugins/clang/implicitboolconversion.cxx | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'compilerplugins/clang') diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index bc18e87cf366..058e042dbcf2 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -284,6 +284,8 @@ public: bool VisitImplicitCastExpr(ImplicitCastExpr const * expr); + bool VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr const * expr); + private: bool isExternCFunctionCall( CallExpr const * expr, FunctionProtoType const ** functionType); @@ -905,6 +907,30 @@ bool ImplicitBoolConversion::VisitImplicitCastExpr( return true; } +bool ImplicitBoolConversion::VisitMaterializeTemporaryExpr( + MaterializeTemporaryExpr const * expr) +{ + if (ignoreLocation(expr)) { + return true; + } + if (auto const sub = dyn_cast(expr->GetTemporaryExpr())) { + auto const subsub = compat::getSubExprAsWritten(sub); + if (subsub->getType().IgnoreParens() == expr->getType().IgnoreParens() + && isBool(subsub)) + { + report( + DiagnosticsEngine::Warning, + ("explicit conversion (%0) from %1 to %2 implicitly converted" + " back to %3"), + expr->getLocStart()) + << sub->getCastKindName() << subsub->getType() << sub->getType() + << expr->getType() << expr->getSourceRange(); + return true; + } + } + return true; +} + bool ImplicitBoolConversion::isExternCFunctionCall( CallExpr const * expr, FunctionProtoType const ** functionType) { -- cgit