bool RefAssign::VisitBinaryOperator(BinaryOperator const* binaryOp)
{ if (ignoreLocation(binaryOp)) returntrue; if (binaryOp->getOpcode() != BO_Assign) returntrue;
// ignore assigning to/from an element of a collection if (isa<CXXOperatorCallExpr>(binaryOp->getLHS()->IgnoreParenImpCasts())) returntrue; if (isa<CXXOperatorCallExpr>(binaryOp->getRHS()->IgnoreParenImpCasts())) returntrue;
// if we are assigning to a parameter we probably mean it if (auto declRefExpr = dyn_cast<DeclRefExpr>(binaryOp->getLHS()->IgnoreParenImpCasts())) if (declRefExpr->getDecl() && isa<ParmVarDecl>(declRefExpr->getDecl())) returntrue;
if (auto callExpr = dyn_cast<CallExpr>(binaryOp->getRHS()->IgnoreParenImpCasts())) if (auto functionDecl = dyn_cast_or_null<FunctionDecl>(callExpr->getCalleeDecl())) if (functionDecl->getIdentifier()
&& (functionDecl->getName() == "min" || functionDecl->getName() == "max")) returntrue;
auto lhsType = ExtractType(binaryOp->getLHS()); auto rhsType = ExtractType(binaryOp->getRHS()); if (!loplugin::TypeCheck(lhsType).LvalueReference()) returntrue; if (!loplugin::TypeCheck(rhsType).LvalueReference()) returntrue;
binaryOp->dump();
report(DiagnosticsEngine::Warning, "assigning a %0 to a var of type %1 probably does not do what you think",
binaryOp->getBeginLoc())
<< rhsType << lhsType << binaryOp->getSourceRange(); 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.