diff --git a/lib/executionpath.cpp b/lib/executionpath.cpp index f4a4a43e7..82168ba66 100644 --- a/lib/executionpath.cpp +++ b/lib/executionpath.cpp @@ -181,8 +181,8 @@ static const Token *checkExecutionPaths_(const Token *tok, std::liststr() == "return") + // return/throw ends all execution paths + if (tok->str() == "return" || tok->str() == "throw") { ExecutionPath::bailOut(checks); } diff --git a/test/testother.cpp b/test/testother.cpp index 208755573..bc1eb8b4f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1245,6 +1245,17 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("int foo()\n" + "{\n" + " int ret;\n" + " if (one())\n" + " ret = 1;\n" + " else\n" + " throw 3;\n" + " return ret;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("int f(int a)\n" "{\n" " int ret;\n"