diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index f8dc0e227..88b1afb60 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1888,6 +1888,9 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, boo else if (!isPointer && Token::Match(tok->previous(), "[(,] %var% [,)]") && isVariableUsage(tok, isPointer, alloc, _tokenizer->isCPP())) return true; + else if (!isPointer && Token::Match(tok->previous(), "= %var% ;")) + return true; + else if (_settings->experimental && !isPointer && Token::Match(tok->tokAt(-2), "[(,] & %var% [,)]") && diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 89d19c5cb..5de982251 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2909,6 +2909,14 @@ private: "}\n", "test.c"); ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: ab.a\n", errout.str()); + checkUninitVar2("struct AB { int a; int b; };\n" + "void f(void) {\n" + " struct AB ab;\n" + " ab.a = 1;\n" + " x = ab;\n" + "}\n", "test.c"); + ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\n", errout.str()); + checkUninitVar2("struct AB { int a; int b; };\n" // pass struct member by address "void f(void) {\n" " struct AB ab;\n"