From 4894cdab8f9eee96e232a51f66cfd0e7e1b0e0ac Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 16 Jul 2022 23:46:55 +0200 Subject: [PATCH] Fix #11108 FP unreadVariable with unique_ptr and unknown c'tor (#4284) * Fix #11108 FP unreadVariable with unique_ptr and unknown c'tor * Fix test --- lib/checkunusedvar.cpp | 2 +- test/testunusedvar.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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)"