Fixed #7144 (Tokenizer::isScopeNoReturn: handling '{ { throw new string(..); } }')

This commit is contained in:
Daniel Marjamäki 2016-01-18 15:39:20 +01:00
parent d656e3a056
commit b9a4a950a2
3 changed files with 10 additions and 0 deletions

View File

@ -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% ("))

View File

@ -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
}
};

View File

@ -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