Fixed #7144 (Tokenizer::isScopeNoReturn: handling '{ { throw new string(..); } }')
This commit is contained in:
parent
d656e3a056
commit
b9a4a950a2
|
@ -292,6 +292,8 @@ bool isReturnScope(const Token * const endToken)
|
||||||
Token::simpleMatch(prev->link()->linkAt(-1)->previous(), "return (")) {
|
Token::simpleMatch(prev->link()->linkAt(-1)->previous(), "return (")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (Token::Match(prev->link()->previous(), "[;{}] {"))
|
||||||
|
return isReturnScope(prev);
|
||||||
} else if (Token::simpleMatch(prev, ";")) {
|
} else if (Token::simpleMatch(prev, ";")) {
|
||||||
// noreturn function
|
// noreturn function
|
||||||
if (Token::simpleMatch(prev->previous(), ") ;") && Token::Match(prev->linkAt(-1)->tokAt(-2), "[;{}] %name% ("))
|
if (Token::simpleMatch(prev->previous(), ") ;") && Token::Match(prev->linkAt(-1)->tokAt(-2), "[;{}] %name% ("))
|
||||||
|
|
|
@ -49,6 +49,8 @@ private:
|
||||||
ASSERT_EQUALS(true, isReturnScope("void f() { if (a) { return; } }", -2));
|
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(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(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
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1222,6 +1222,12 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
|
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)
|
// if (var)
|
||||||
code = "void f(int x) {\n"
|
code = "void f(int x) {\n"
|
||||||
" if (x) { a = x; }\n" // <- x is not 0
|
" if (x) { a = x; }\n" // <- x is not 0
|
||||||
|
|
Loading…
Reference in New Issue