diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index a69351727..960a22016 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1616,6 +1616,8 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str return true; else if ((tok->previous() && tok->previous()->isConstOp()) || Token::Match(tok->previous(), "[|=")) ; // member variable usage + else if (tok->tokAt(3)->isConstOp()) + ; // member variable usage else return true; } else if (tok->strAt(1) == "=") diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index b1ad18d24..dfa6b30b2 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2713,6 +2713,13 @@ private: "}\n", "test.c"); ASSERT_EQUALS("[test.c:9]: (error) Uninitialized struct member: fred.b\n", errout.str()); + checkUninitVar2("struct Fred { int a; };\n" + "void f() {\n" + " struct Fred fred;\n" + " if (fred.a==1) {}\n" + "}", "test.c"); + ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: fred.a\n", errout.str()); + checkUninitVar2("struct S { int n; int m; };\n" "void f(void) {\n" " struct S s;\n"