diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 52d9834b1..940c93f0e 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -465,7 +465,7 @@ private: } // Used.. - if (Token::Match(tok.previous(), "[[(,+-*/] %var% []),;+-*/]")) + if (Token::Match(tok.previous(), "[[(,+-*/=] %var% []),;+-*/]")) { use(checks, &tok); return &tok; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 546638ad4..d9b396e4f 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -73,6 +73,12 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str()); + checkUninitVar("void foo() {\n" + " int a;\n" + " b = a - c;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str()); + // dereferencing uninitialized pointer.. checkUninitVar("static void foo()\n" "{\n"