diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 04d0f54db..1d7eb8c00 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1458,6 +1458,13 @@ void CheckOther::uninitvar() unsigned int indentlevel = 0; for (; tok; tok = tok->next()) { + // skip structs + if (Token::Match(tok->previous(), "[;{}] struct %var% {")) + { + tok = tok->tokAt(2)->link(); + continue; + } + if (tok->str() == "{") ++indentlevel; else if (tok->str() == "}") diff --git a/test/testother.cpp b/test/testother.cpp index aa14b8475..8dacf4722 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1229,6 +1229,18 @@ private: " char *s2 = new char[strlen(s1)];\n" "};\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s1\n", errout.str()); + + // struct.. + checkUninitVar("void f()\n" + "{\n" + " struct Relative {\n" + " Surface *surface;\n" + " void MoveTo(int x, int y) {\n" + " surface->MoveTo();\n" + " }\n" + " };\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); }