diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index ebdf008db..0708e2bcf 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -413,7 +413,7 @@ private: // Variable declaration.. if (tok.varId() && Token::Match(&tok, "%var% [[;]")) { const Variable* var2 = tok.variable(); - if (var2 && var2->nameToken() == &tok && !var2->isStatic() && !var2->isExtern() && !var2->isConst()) { + if (var2 && var2->nameToken() == &tok && !var2->isStatic() && !var2->isExtern() && !var2->isConst() && !Token::simpleMatch(tok.linkAt(1), "] [")) { if (tok.linkAt(1)) { // array const Token* endtok = tok.next(); while (endtok->link()) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 78aadc953..58a387747 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1305,6 +1305,13 @@ private: " return a[0][1];\n" "}"); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", "", errout.str()); + + // # 4740 + checkUninitVar("void f() {\n" + " int *a[2][19];\n" + " int **b = a[0];\n" + "}"); + ASSERT_EQUALS("", errout.str()); } // alloc..