/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ #ifndef LO_CLANG_SHARED_PLUGINS
bool MapIndex::VisitMemberExpr(const MemberExpr* memberExpr)
{ if (ignoreLocation(memberExpr)) returntrue; // operator bool conversion auto conversionDecl = dyn_cast<CXXConversionDecl>(memberExpr->getMemberDecl()); if (!conversionDecl || !conversionDecl->getConversionType()->isBooleanType()) returntrue; auto operatorCall = dyn_cast<CXXOperatorCallExpr>(memberExpr->getBase()->IgnoreCasts()); if (!operatorCall) returntrue; if (operatorCall->getOperator() != OverloadedOperatorKind::OO_Subscript) returntrue; auto tc = loplugin::TypeCheck(operatorCall->getArg(0)->getType()); if (!tc.Class("map") && !tc.Class("unordered_map")) returntrue;
report(DiagnosticsEngine::Warning, "will create an empty entry in the map, you sure about that, rather use count()1",
operatorCall->getExprLoc()); returntrue;
}
bool MapIndex::VisitImplicitCastExpr(const ImplicitCastExpr* implicitCastExpr)
{ if (ignoreLocation(implicitCastExpr))
{ returntrue;
}
// first cast is some kind of "ToBoolean" cast auto ck = implicitCastExpr->getCastKind(); if (ck != CK_MemberPointerToBoolean && ck != CK_PointerToBoolean && ck != CK_IntegralToBoolean
&& ck != CK_FloatingToBoolean && ck != CK_FloatingComplexToBoolean
&& ck != CK_IntegralComplexToBoolean) returntrue;
// second cast is LValueToRValue
implicitCastExpr = dyn_cast<ImplicitCastExpr>(implicitCastExpr->getSubExpr()); if (!implicitCastExpr) returntrue;
if (implicitCastExpr->getCastKind() != CK_LValueToRValue) returntrue; auto operatorCall = dyn_cast<CXXOperatorCallExpr>(implicitCastExpr->getSubExpr()); if (!operatorCall) returntrue; if (operatorCall->getOperator() != OverloadedOperatorKind::OO_Subscript) returntrue; auto tc = loplugin::TypeCheck(operatorCall->getArg(0)->getType()); if (!tc.Class("map") && !tc.Class("unordered_map")) returntrue;
report(DiagnosticsEngine::Warning, "will create an empty entry in the map, you sure about that, rather use count()2",
implicitCastExpr->getExprLoc()); returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.