diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 57b070b9a..0fb48ed37 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -137,8 +137,11 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set if (tok->isStandardType() || tok->isEnumType()) stdtype = true; } - if (var.isArray() && !stdtype) - continue; + 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; + } while (tok && tok->str() != ";") tok = tok->next(); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 15fe8b54a..ac8787125 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1773,6 +1773,18 @@ private: " fred[1].x = 0;\n" "}", "test.c"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("char f() {\n" + " std::array 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 a;\n" + " return a[0];\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void uninitvar_pointertoarray() {