diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d44f43639..8f99d0e54 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1537,7 +1537,9 @@ private: break; if (Token::Match(tok2, "%var% (")) break; - if (tok2->varId() && !Token::simpleMatch(tok2->next(), "=")) + if (tok2->varId() && + !Token::simpleMatch(tok2->previous(), "&") && + !Token::simpleMatch(tok2->next(), "=")) use(foundError, checks, tok2); } } diff --git a/test/testother.cpp b/test/testother.cpp index 138f0d115..b55675673 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1020,6 +1020,13 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str()); + checkUninitVar("void foo()\n" + "{\n" + " int x;\n" + " int *y = &x;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("static int foo()\n" "{\n" " int ret;\n"