diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index da2587cd4..630ad66d8 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1199,7 +1199,7 @@ void CheckUnusedVar::checkFunctionVariableUsage() if (tok->str() == "=" && !(tok->valueType() && tok->valueType()->pointer) && isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false)) continue; - const bool isPointer = tok->valueType() && tok->valueType()->pointer; + const bool isPointer = tok->valueType() && (tok->valueType()->pointer || tok->valueType()->type == ValueType::SMART_POINTER); if (tok->isName()) { if (isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false)) diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 8ff2097f1..459a4a33e 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -6012,6 +6012,12 @@ private: " return *p;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("struct S { S(); };\n" // #11108 + "void f(std::unique_ptr p) {\n" + " p = nullptr;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } // ticket #3104 - false positive when variable is read with "if (NOT var)"