summaryrefslogtreecommitdiffstats
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-12-17 23:53:34 +0100
committerStephan Bergmann <sbergman@redhat.com>2021-12-18 07:42:35 +0100
commit5804d0a2b94b34ca9cdfb8f75065d008f582be7e (patch)
tree039a115a055db8ddfb679400a6fff78be111611e /compilerplugins
parenttdf#144364 sw: Revert "Use FastParser in SwXMLTextBlocks" (diff)
downloadcore-5804d0a2b94b34ca9cdfb8f75065d008f582be7e.tar.gz
core-5804d0a2b94b34ca9cdfb8f75065d008f582be7e.zip
Fix loplugin:unusedvariablecheck
...after a214369f14d3f53d45b1889827057882c0ffd62e "loplugin:unusedvariablecheck improve", so that it doesn't cause false positives for > CoIfPtr<IADsADSystemInfo> aADsysGuard(pADsys); and > CoIfPtr<IADsUser> pUserGuard(pUser); in (Windows-only) extensions/source/config/WinUserInfo/WinUserInfoBe.cxx, where the CoIfPtr default constructor is > CoIfPtr(If* p = nullptr) Change-Id: I6107fa8d8aa7244b2fc5c50df2baea5096d46214 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127017 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/test/unusedvariablecheck.cxx7
-rw-r--r--compilerplugins/clang/unusedvariablecheck.cxx3
2 files changed, 9 insertions, 1 deletions
diff --git a/compilerplugins/clang/test/unusedvariablecheck.cxx b/compilerplugins/clang/test/unusedvariablecheck.cxx
index e53da1be40a8..b020fba3eb4e 100644
--- a/compilerplugins/clang/test/unusedvariablecheck.cxx
+++ b/compilerplugins/clang/test/unusedvariablecheck.cxx
@@ -19,6 +19,11 @@ namespace
template <typename T> using Vec = std::vector<T>;
}
+struct S : std::unique_ptr<int>
+{
+ S(int* = nullptr);
+};
+
int main()
{
std::list<int> v1; // expected-error {{unused variable 'v1' [loplugin:unusedvariablecheck]}}
@@ -26,6 +31,8 @@ int main()
Vec<int> v3; // expected-error {{unused variable 'v3' [loplugin:unusedvariablecheck]}}
std::unique_ptr<int>
v4; // expected-error {{unused variable 'v4' [loplugin:unusedvariablecheck]}}
+ S v5; // expected-error {{unused variable 'v5' [loplugin:unusedvariablecheck]}}
+ S v6(nullptr);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/unusedvariablecheck.cxx b/compilerplugins/clang/unusedvariablecheck.cxx
index 73529e118bf4..c3adfa5b726e 100644
--- a/compilerplugins/clang/unusedvariablecheck.cxx
+++ b/compilerplugins/clang/unusedvariablecheck.cxx
@@ -106,7 +106,8 @@ bool UnusedVariableCheck::isUnusedSmartPointer( const VarDecl* var )
auto cxxConstructExpr = dyn_cast<CXXConstructExpr>(var->getInit());
if (!cxxConstructExpr)
return false;
- return cxxConstructExpr->getConstructor()->isDefaultConstructor();
+ return
+ cxxConstructExpr->getNumArgs() == 0 || cxxConstructExpr->getArg(0)->isDefaultArgument();
}
static Plugin::Registration< UnusedVariableCheck > unusedvariablecheck( "unusedvariablecheck" );