compilerplugins/clang/test/unusedvariablecheck.cxx | 7 +++++++ compilerplugins/clang/unusedvariablecheck.cxx | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-)
New commits: commit 5804d0a2b94b34ca9cdfb8f75065d008f582be7e Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Fri Dec 17 23:53:34 2021 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Sat Dec 18 07:42:35 2021 +0100 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 <sberg...@redhat.com> 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" );