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
This commit is contained in:
chrchr-github 2022-07-16 23:46:55 +02:00 committed by GitHub
parent b16d12b5fb
commit 4894cdab8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -1199,7 +1199,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
if (tok->str() == "=" && !(tok->valueType() && tok->valueType()->pointer) && isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false)) if (tok->str() == "=" && !(tok->valueType() && tok->valueType()->pointer) && isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false))
continue; 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 (tok->isName()) {
if (isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false)) if (isRaiiClass(tok->valueType(), mTokenizer->isCPP(), false))

View File

@ -6012,6 +6012,12 @@ private:
" return *p;\n" " return *p;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
functionVariableUsage("struct S { S(); };\n" // #11108
"void f(std::unique_ptr<S> p) {\n"
" p = nullptr;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
// ticket #3104 - false positive when variable is read with "if (NOT var)" // ticket #3104 - false positive when variable is read with "if (NOT var)"