loplugin:overrideparam enable checking that default values match

Change-Id: I4ca21d12d6f5dd4bb0b2705f7e36249082b0838c
This commit is contained in:
Noel Grandin
2016-07-25 08:14:06 +02:00
parent 15613117f9
commit 594dd232c8

View File

@@ -104,7 +104,6 @@ bool OverrideParam::VisitCXXMethodDecl(const CXXMethodDecl * methodDecl) {
}
else if (parmVarDecl->hasDefaultArg() && superParmVarDecl->hasDefaultArg()
&& !hasSameDefaultParams(parmVarDecl, superParmVarDecl)) {
/* do nothing for now, will enable this in a later commit
report(
DiagnosticsEngine::Warning,
"overridden method declaration has different default param to super-method",
@@ -115,7 +114,6 @@ bool OverrideParam::VisitCXXMethodDecl(const CXXMethodDecl * methodDecl) {
"original param here",
superParmVarDecl->getSourceRange().getBegin())
<< superParmVarDecl->getSourceRange();
*/
}
/* do nothing for now, will enable this in a later commit
if (methodDecl->isThisDeclarationADefinition() && parmVarDecl->getName().empty()) {
@@ -162,12 +160,23 @@ bool OverrideParam::hasSameDefaultParams(const ParmVarDecl * parmVarDecl, const
{
return x1 == x2;
}
APFloat f1(0.0f), f2(0.0f);
if (defaultArgExpr->EvaluateAsFloat(f1, compiler.getASTContext())
&& superDefaultArgExpr->EvaluateAsFloat(f2, compiler.getASTContext()))
{
return f1.bitwiseIsEqual(f2);
}
// catch params with defaults like "= OUString()"
if (isa<MaterializeTemporaryExpr>(defaultArgExpr)
&& isa<MaterializeTemporaryExpr>(superDefaultArgExpr))
{
return true;
}
if (isa<CXXBindTemporaryExpr>(defaultArgExpr)
&& isa<CXXBindTemporaryExpr>(superDefaultArgExpr))
{
return true;
}
return false;
}