diff options
-rw-r--r-- | compilerplugins/clang/test/unusedvariablecheck.cxx | 7 | ||||
-rw-r--r-- | compilerplugins/clang/unusedvariablecheck.cxx | 3 |
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" ); |