Fix FN uninitVar with std::array (#3707)

This commit is contained in:
chrchr-github 2022-01-27 19:45:27 +01:00 committed by GitHub
parent f429245da2
commit c74eeb6bad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -137,8 +137,11 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string>
if (tok->isStandardType() || tok->isEnumType()) if (tok->isStandardType() || tok->isEnumType())
stdtype = true; stdtype = true;
} }
if (var.isArray() && !stdtype) if (var.isArray() && !stdtype) { // std::array
continue; if (!(var.isStlType() && Token::simpleMatch(var.typeStartToken(), "std :: array") && var.valueType() &&
var.valueType()->containerTypeToken && var.valueType()->containerTypeToken->isStandardType()))
continue;
}
while (tok && tok->str() != ";") while (tok && tok->str() != ";")
tok = tok->next(); tok = tok->next();

View File

@ -1773,6 +1773,18 @@ private:
" fred[1].x = 0;\n" " fred[1].x = 0;\n"
"}", "test.c"); "}", "test.c");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("char f() {\n"
" std::array<char, 1> a;\n"
" return a[0];\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("std::string f() {\n"
" std::array<std::string, 1> a;\n"
" return a[0];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void uninitvar_pointertoarray() { void uninitvar_pointertoarray() {