Fix #11094 FP unreadVariable with unique_ptr and unknown type (#4140)

This commit is contained in:
chrchr-github 2022-05-27 17:17:50 +02:00 committed by GitHub
parent 558e00272d
commit d5d6da0dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -61,7 +61,7 @@ static bool isRaiiClass(const ValueType *valueType, bool cpp, bool defaultReturn
if (!valueType)
return defaultReturn;
if (valueType->smartPointerType && isRaiiClassScope(valueType->smartPointerType->classScope))
if ((valueType->smartPointerType && isRaiiClassScope(valueType->smartPointerType->classScope)) || (!valueType->smartPointerType && valueType->type == ValueType::Type::SMART_POINTER))
return true;
switch (valueType->type) {

View File

@ -5910,6 +5910,14 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (style) Variable 'a' is assigned a value that is never used.\n"
"[test.cpp:8]: (style) Variable 'a2' is assigned a value that is never used.\n", errout.str());
functionVariableUsage("void g();\n" // #11094
"void f() {\n"
" auto p = std::make_unique<S>();\n"
" p = nullptr;\n"
" g();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
// ticket #3104 - false positive when variable is read with "if (NOT var)"