bool UnusedVariableCheck::VisitVarDecl( const VarDecl* var )
{ if( ignoreLocation( var )) returntrue; if( var->isReferenced() || var->isUsed()) returntrue; if( var->isDefinedOutsideFunctionOrMethod()) returntrue;
auto type = var->getType(); bool check = loplugin::isExtraWarnUnusedType(type);
if (!check)
check = isUnusedSmartPointer(var);
// this chunk of logic generates false+, which is why we don't leave it on /* if(!check&&type->isRecordType()) { autorecordDecl =dyn_cast_or_null<CXXRecordDecl>(type->getAs<RecordType>()->getDecl()); if(recordDecl&&recordDecl->hasDefinition()&&recordDecl->hasTrivialDestructor()) check=true; }
*/ if(check)
{ if( const ParmVarDecl* param = dyn_cast< ParmVarDecl >( var ))
{ if( !param->getDeclName()) returntrue; // unnamed parameter -> unused // If this declaration does not have a body, then the parameter is indeed not used, // so ignore. autoconst parent = param->getParentFunctionOrMethod(); if( const FunctionDecl* func = dyn_cast_or_null< FunctionDecl >( parent)) if( !func->doesThisDeclarationHaveABody() || func->getBody() == nullptr) returntrue; if (autoconst d = dyn_cast_or_null<ObjCMethodDecl>(parent)) { if (!d->hasBody()) { returntrue;
}
}
report( DiagnosticsEngine::Warning, "unused parameter %0",
var->getLocation()) << var->getDeclName();
} else
report( DiagnosticsEngine::Warning, "unused variable %0",
var->getLocation()) << var->getDeclName();
} returntrue;
}
bool UnusedVariableCheck::isUnusedSmartPointer( const VarDecl* var )
{ // if we have a var of smart-pointer type, and that var is both uninitialised and // not referenced, then we can remove it if (!isSmartPointerType(var->getType())) returnfalse;
if (!var->hasInit()) returntrue;
auto cxxConstructExpr = dyn_cast<CXXConstructExpr>(var->getInit()); if (!cxxConstructExpr) returnfalse; return
cxxConstructExpr->getNumArgs() == 0 || cxxConstructExpr->getArg(0)->isDefaultArgument();
}
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.