summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/defaultparams.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/defaultparams.cxx')
-rw-r--r--compilerplugins/clang/defaultparams.cxx19
1 files changed, 16 insertions, 3 deletions
diff --git a/compilerplugins/clang/defaultparams.cxx b/compilerplugins/clang/defaultparams.cxx
index de030870a7f9..7755b3749661 100644
--- a/compilerplugins/clang/defaultparams.cxx
+++ b/compilerplugins/clang/defaultparams.cxx
@@ -26,6 +26,8 @@ public:
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
bool VisitCallExpr(CallExpr * callExpr);
+private:
+ bool evaluate(const Expr* expr, APSInt& x);
};
bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
@@ -69,9 +71,7 @@ bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
if (!found)
{
APSInt x1, x2;
- if (defaultArgExpr->EvaluateAsInt(x1, compiler.getASTContext())
- && arg->EvaluateAsInt(x2, compiler.getASTContext())
- && x1 == x2)
+ if (evaluate(defaultArgExpr, x1) && evaluate(arg, x2) && x1 == x2)
{
found = true;
}
@@ -108,6 +108,19 @@ bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
return true;
}
+bool DefaultParams::evaluate(const Expr* expr, APSInt& x)
+{
+ if (isa<CXXNullPtrLiteralExpr>(expr)) {
+ x = 0;
+ return true;
+ }
+ if (expr->EvaluateAsInt(x, compiler.getASTContext()))
+ {
+ return true;
+ }
+ return false;
+}
+
loplugin::Plugin::Registration< DefaultParams > X("defaultparams");
}