Better handling functions with try block for throwInNoexceptFunction (#3264)

This commit is contained in:
Maksim Derbasov 2021-05-22 09:36:28 +03:00 committed by GitHub
parent 1e3ab460a3
commit f0d1822a83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -207,10 +207,8 @@ static const Token * functionThrowsRecursive(const Function * function, std::set
for (const Token *tok = function->functionScope->bodyStart->next();
tok != function->functionScope->bodyEnd; tok = tok->next()) {
if (tok->str() == "try") {
// just bail for now
break;
}
if (Token::simpleMatch(tok, "try {"))
tok = tok->linkAt(1); // skip till start of catch clauses
if (tok->str() == "throw") {
return tok;
} else if (tok->function()) {
@ -232,7 +230,7 @@ static const Token * functionThrowsRecursive(const Function * function, std::set
static const Token * functionThrows(const Function * function)
{
std::set<const Function *> recursive;
std::set<const Function *> recursive;
return functionThrowsRecursive(function, recursive);
}
@ -306,4 +304,3 @@ void CheckExceptionSafety::unhandledExceptionSpecification()
}
}
}

View File

@ -321,7 +321,7 @@ private:
}
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 func3() noexcept(true) { 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());
// 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());
}
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 func3() throw(int) { throw 1; }\n"
"void func4() throw() { func1(); }\n"