summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-10-26 21:04:40 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-10-26 21:07:17 +0200
commit1061875d6747f3cb89466aa6df568620a7ddfa05 (patch)
treec6e60cd72a1af5d50ac4de413fce9d0b07037157 /compilerplugins
parente02e0f4081c0807fa65548159292585c680abff3 (diff)
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
Diffstat (limited to 'compilerplugins')
-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)
{