Avoid FP exceptThrowInNoThrowFunction and exceptThrowInNoexecptFunction

This commit is contained in:
Alexander Mai 2014-04-10 21:55:49 +02:00
parent e39b89efc3
commit 559a2bc2c8
2 changed files with 10 additions and 2 deletions

View File

@ -192,7 +192,7 @@ void CheckExceptionSafety::noexceptThrows()
if (scope->function && scope->function->isNoExcept &&
(!scope->function->noexceptArg || scope->function->noexceptArg->str() == "true")) {
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (tok->str() != "throw") {
if (tok->str() == "throw") {
noexceptThrowError(tok);
}
}
@ -213,7 +213,7 @@ void CheckExceptionSafety::nothrowThrows()
// onlycheck throw() functions
if (scope->function && scope->function->isThrow && !scope->function->throwArg) {
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
if (tok->str() != "throw") {
if (tok->str() == "throw") {
nothrowThrowError(tok);
}
}

View File

@ -317,12 +317,20 @@ private:
"void func3() noexcept(false) { throw 1; }\n");
ASSERT_EQUALS("[test.cpp:1]: (error) Exception thrown in noexcept function.\n"
"[test.cpp:2]: (error) Exception thrown in noexcept function.\n", errout.str());
// avoid false positives
check("const char *func() noexcept { return 0; }\n");
ASSERT_EQUALS("", errout.str());
}
void nothrowThrow() {
check("void func1() throw() { throw 1; }\n"
"void func2() throw(int) { throw 1; }\n");
ASSERT_EQUALS("[test.cpp:1]: (error) Exception thrown in throw() function.\n", errout.str());
// avoid false positives
check("const char *func() throw() { return 0; }\n");
ASSERT_EQUALS("", errout.str());
}
};