summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-05-03 09:29:37 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-05-03 14:03:54 +0200
commit7cc1d3437a48140382773bf41401a46a3ced4706 (patch)
tree5e038178bb0b2699bb9314bd02fb7e197597ecb2 /compilerplugins
parentb912eafa33227a5622c5a4310948cfa07c984726 (diff)
loplugin:unnecessaryparen small improvement
when calling a function, and passing only one arg, but the function has defaulted args, we were ignoring this case. Change-Id: I86517f18e30531127664088ddc09ef96dbd8bdf5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115033 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/test/unnecessaryparen.cxx2
-rw-r--r--compilerplugins/clang/unnecessaryparen.cxx9
2 files changed, 10 insertions, 1 deletions
diff --git a/compilerplugins/clang/test/unnecessaryparen.cxx b/compilerplugins/clang/test/unnecessaryparen.cxx
index f932cd312558..ccc2b4ce6556 100644
--- a/compilerplugins/clang/test/unnecessaryparen.cxx
+++ b/compilerplugins/clang/test/unnecessaryparen.cxx
@@ -113,6 +113,8 @@ int main()
BrowseMode nBits = ( BrowseMode::Modules | BrowseMode::Top ); // expected-error {{parentheses immediately inside vardecl statement [loplugin:unnecessaryparen]}}
(void)nBits;
+
+ OUString::number((v2+1)); // expected-error {{parentheses immediately inside single-arg call [loplugin:unnecessaryparen]}}
};
struct B { operator bool() const; };
diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx
index d39dd074eb43..eb53c449cd77 100644
--- a/compilerplugins/clang/unnecessaryparen.cxx
+++ b/compilerplugins/clang/unnecessaryparen.cxx
@@ -368,9 +368,16 @@ bool UnnecessaryParen::VisitCallExpr(const CallExpr* callExpr)
{
if (ignoreLocation(callExpr))
return true;
- if (callExpr->getNumArgs() != 1 || isa<CXXOperatorCallExpr>(callExpr))
+ if (callExpr->getNumArgs() == 0 || isa<CXXOperatorCallExpr>(callExpr))
return true;
+ // if we are calling a >1 arg method, are we using the defaults?
+ if (callExpr->getNumArgs() > 1)
+ {
+ if (!isa<CXXDefaultArgExpr>(callExpr->getArg(1)))
+ return true;
+ }
+
auto parenExpr = dyn_cast<ParenExpr>(ignoreAllImplicit(callExpr->getArg(0)));
if (!parenExpr)
return true;