diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 21bc2e2c9..59330843c 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -292,6 +292,8 @@ bool isReturnScope(const Token * const endToken) Token::simpleMatch(prev->link()->linkAt(-1)->previous(), "return (")) { return true; } + if (Token::Match(prev->link()->previous(), "[;{}] {")) + return isReturnScope(prev); } else if (Token::simpleMatch(prev, ";")) { // noreturn function if (Token::simpleMatch(prev->previous(), ") ;") && Token::Match(prev->linkAt(-1)->tokAt(-2), "[;{}] %name% (")) diff --git a/test/testastutils.cpp b/test/testastutils.cpp index c3d50d6bc..acf1abd0b 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -49,6 +49,8 @@ private: ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return; } }", -2)); ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return (ab){0}; } }", -2)); // #7103 ASSERT_EQUALS(false, isReturnScope("void f() { if (a) { return (ab){0}; } }", -4)); // #7103 + ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -4)); // #7144 + ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { {throw new string(x);}; } }", -2)); // #7144 } }; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index c1dce4c27..d91067bbb 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1222,6 +1222,12 @@ private: "}"; ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); + code = "void f(int x) {\n" + " if (!x) { { throw new string(); }; }\n" + " a = x;\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); + // if (var) code = "void f(int x) {\n" " if (x) { a = x; }\n" // <- x is not 0