diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index d0d6e0b88..bc068fb01 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1182,7 +1182,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int return true; } - if (Token::Match(tok, "return|break|continue|throw")) + if (Token::Match(tok, "return|break|continue|throw|goto")) ret = true; else if (ret && tok->str() == ";") return true; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 23e0c00e7..72c589f3b 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1801,7 +1801,7 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); - // return, break, continue + // return, break, continue, goto checkUninitVar2("void f() {\n" " int x;\n" " if (y == 1) { return; }\n" @@ -1820,6 +1820,17 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar2("void f() {\n" + " int i;\n" + " if (x) {\n" + " i = 1;\n" + " } else {\n" + " goto out;\n" + " }\n" + " i++;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // for, while checkUninitVar2("void f() {\n" " int x;\n"