Fix FN uninitVar with std::array (#3707)
This commit is contained in:
parent
f429245da2
commit
c74eeb6bad
|
@ -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
|
||||||
|
if (!(var.isStlType() && Token::simpleMatch(var.typeStartToken(), "std :: array") && var.valueType() &&
|
||||||
|
var.valueType()->containerTypeToken && var.valueType()->containerTypeToken->isStandardType()))
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
while (tok && tok->str() != ";")
|
while (tok && tok->str() != ";")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue