Better handling functions with try block for throwInNoexceptFunction (#3264)
This commit is contained in:
parent
1e3ab460a3
commit
f0d1822a83
|
@ -207,10 +207,8 @@ static const Token * functionThrowsRecursive(const Function * function, std::set
|
||||||
|
|
||||||
for (const Token *tok = function->functionScope->bodyStart->next();
|
for (const Token *tok = function->functionScope->bodyStart->next();
|
||||||
tok != function->functionScope->bodyEnd; tok = tok->next()) {
|
tok != function->functionScope->bodyEnd; tok = tok->next()) {
|
||||||
if (tok->str() == "try") {
|
if (Token::simpleMatch(tok, "try {"))
|
||||||
// just bail for now
|
tok = tok->linkAt(1); // skip till start of catch clauses
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (tok->str() == "throw") {
|
if (tok->str() == "throw") {
|
||||||
return tok;
|
return tok;
|
||||||
} else if (tok->function()) {
|
} else if (tok->function()) {
|
||||||
|
@ -306,4 +304,3 @@ void CheckExceptionSafety::unhandledExceptionSpecification()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -321,7 +321,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void noexceptThrow() {
|
void noexceptThrow() {
|
||||||
check("void func1() noexcept(false) { throw 1; }\n"
|
check("void func1() noexcept(false) { try {} catch(...) {;} throw 1; }\n"
|
||||||
"void func2() noexcept { throw 1; }\n"
|
"void func2() noexcept { throw 1; }\n"
|
||||||
"void func3() noexcept(true) { throw 1; }\n"
|
"void func3() noexcept(true) { throw 1; }\n"
|
||||||
"void func4() noexcept(false) { throw 1; }\n"
|
"void func4() noexcept(false) { throw 1; }\n"
|
||||||
|
@ -332,12 +332,13 @@ private:
|
||||||
"[test.cpp:5]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str());
|
"[test.cpp:5]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str());
|
||||||
|
|
||||||
// avoid false positives
|
// avoid false positives
|
||||||
check("const char *func() noexcept { return 0; }");
|
check("const char *func() noexcept { return 0; }\n"
|
||||||
|
"const char *func1() noexcept { try { throw 1; } catch(...) {} return 0; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void nothrowThrow() {
|
void nothrowThrow() {
|
||||||
check("void func1() throw(int) { throw 1; }\n"
|
check("void func1() throw(int) { try {;} catch(...) { throw 1; } ; }\n"
|
||||||
"void func2() throw() { throw 1; }\n"
|
"void func2() throw() { throw 1; }\n"
|
||||||
"void func3() throw(int) { throw 1; }\n"
|
"void func3() throw(int) { throw 1; }\n"
|
||||||
"void func4() throw() { func1(); }\n"
|
"void func4() throw() { func1(); }\n"
|
||||||
|
|
Loading…
Reference in New Issue