Skip to content

Commit c74eeb6

Browse files
Fix FN uninitVar with std::array (#3707)
1 parent f429245 commit c74eeb6

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/checkuninitvar.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string>
137137
if (tok->isStandardType() || tok->isEnumType())
138138
stdtype = true;
139139
}
140-
if (var.isArray() && !stdtype)
141-
continue;
140+
if (var.isArray() && !stdtype) { // std::array
141+
if (!(var.isStlType() && Token::simpleMatch(var.typeStartToken(), "std :: array") && var.valueType() &&
142+
var.valueType()->containerTypeToken && var.valueType()->containerTypeToken->isStandardType()))
143+
continue;
144+
}
142145

143146
while (tok && tok->str() != ";")
144147
tok = tok->next();

test/testuninitvar.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,18 @@ class TestUninitVar : public TestFixture {
17731773
" fred[1].x = 0;\n"
17741774
"}", "test.c");
17751775
ASSERT_EQUALS("", errout.str());
1776+
1777+
checkUninitVar("char f() {\n"
1778+
" std::array<char, 1> a;\n"
1779+
" return a[0];\n"
1780+
"}\n");
1781+
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
1782+
1783+
checkUninitVar("std::string f() {\n"
1784+
" std::array<std::string, 1> a;\n"
1785+
" return a[0];\n"
1786+
"}\n");
1787+
ASSERT_EQUALS("", errout.str());
17761788
}
17771789

17781790
void uninitvar_pointertoarray() {

0 commit comments

Comments
 (0)