summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/implicitboolconversion.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/implicitboolconversion.cxx')
-rw-r--r--compilerplugins/clang/implicitboolconversion.cxx26
1 files changed, 26 insertions, 0 deletions
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<ExplicitCastExpr>(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)
{