summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2015-08-12 15:09:36 +0200
committerNoel Grandin <noel@peralex.com>2015-08-14 10:52:46 +0200
commit860130783830fc39ea49a3c76f70ab79b4f31f92 (patch)
tree454924b0228fbe92f5fff736779fec41094334f5 /compilerplugins
parent70a30fd179266f65500b880ccb0f87011b670fca (diff)
loplugin: defaultparams
Change-Id: Id0a933d3507bc0f8145afa04effadf8475c8e210
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/defaultparams.cxx26
1 files changed, 15 insertions, 11 deletions
diff --git a/compilerplugins/clang/defaultparams.cxx b/compilerplugins/clang/defaultparams.cxx
index 76cbeed2abaa..4127aa305ba9 100644
--- a/compilerplugins/clang/defaultparams.cxx
+++ b/compilerplugins/clang/defaultparams.cxx
@@ -25,10 +25,10 @@ public:
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
- bool VisitCallExpr(const CallExpr * callExpr);
+ bool VisitCallExpr(CallExpr * callExpr);
};
-bool DefaultParams::VisitCallExpr(const CallExpr * callExpr) {
+bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
if (ignoreLocation(callExpr)) {
return true;
}
@@ -40,18 +40,22 @@ bool DefaultParams::VisitCallExpr(const CallExpr * callExpr) {
}
const FunctionDecl* functionDecl = callExpr->getDirectCallee()->getCanonicalDecl();
unsigned i = callExpr->getNumArgs() - 1;
- const Expr* arg = callExpr->getArg(i);
+ Expr* arg = callExpr->getArg(i);
// variadic functions
if (i >= functionDecl->getNumParams()) {
return true;
}
+ if (arg->isDefaultArgument()) {
+ return true;
+ }
+ // ignore this, it seems to trigger an infinite recursion
+ if (isa<UnaryExprOrTypeTraitExpr>(arg))
+ return true;
const ParmVarDecl* parmVarDecl = functionDecl->getParamDecl(i);
const Expr* defaultArgExpr = parmVarDecl->getDefaultArg();
- if (!arg->isDefaultArgument() &&
- arg->isIntegerConstantExpr(compiler.getASTContext()) &&
- parmVarDecl->hasDefaultArg() &&
- !parmVarDecl->hasUninstantiatedDefaultArg() &&
- defaultArgExpr->isIntegerConstantExpr(compiler.getASTContext()))
+ if (parmVarDecl->hasDefaultArg() &&
+ defaultArgExpr &&
+ defaultArgExpr->getType()->isIntegralType(compiler.getASTContext()))
{
APSInt x1, x2;
if (arg->EvaluateAsInt(x1, compiler.getASTContext()) &&
@@ -63,17 +67,17 @@ bool DefaultParams::VisitCallExpr(const CallExpr * callExpr) {
"not necessary to pass this argument, it defaults to the same value",
arg->getSourceRange().getBegin())
<< arg->getSourceRange();
- report(
+ /*report(
DiagnosticsEngine::Warning,
"default method parameter declaration here",
parmVarDecl->getSourceRange().getBegin())
- << parmVarDecl->getSourceRange();
+ << parmVarDecl->getSourceRange();*/
}
}
return true;
}
-loplugin::Plugin::Registration< DefaultParams > X("defaultparams", false);
+loplugin::Plugin::Registration< DefaultParams > X("defaultparams");
}