diff options
author | Noel Grandin <noel@peralex.com> | 2016-07-25 08:14:06 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2016-07-25 08:14:06 +0200 |
commit | 594dd232c8ff4808d4ad43cc41a9934a9c6d131d (patch) | |
tree | 95cba19be29d1965d98d5c1ae9888712cf072cb0 /compilerplugins | |
parent | 15613117f9c825aa8309b456e55fe954ec05475c (diff) |
loplugin:overrideparam enable checking that default values match
Change-Id: I4ca21d12d6f5dd4bb0b2705f7e36249082b0838c
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/overrideparam.cxx | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/compilerplugins/clang/overrideparam.cxx b/compilerplugins/clang/overrideparam.cxx index c04165bbd8c2..c6490d8712bc 100644 --- a/compilerplugins/clang/overrideparam.cxx +++ b/compilerplugins/clang/overrideparam.cxx @@ -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; } |