Avoid FP exceptThrowInNoThrowFunction and exceptThrowInNoexecptFunction
This commit is contained in:
parent
e39b89efc3
commit
559a2bc2c8
|
@ -192,7 +192,7 @@ void CheckExceptionSafety::noexceptThrows()
|
||||||
if (scope->function && scope->function->isNoExcept &&
|
if (scope->function && scope->function->isNoExcept &&
|
||||||
(!scope->function->noexceptArg || scope->function->noexceptArg->str() == "true")) {
|
(!scope->function->noexceptArg || scope->function->noexceptArg->str() == "true")) {
|
||||||
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (tok->str() != "throw") {
|
if (tok->str() == "throw") {
|
||||||
noexceptThrowError(tok);
|
noexceptThrowError(tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ void CheckExceptionSafety::nothrowThrows()
|
||||||
// onlycheck throw() functions
|
// onlycheck throw() functions
|
||||||
if (scope->function && scope->function->isThrow && !scope->function->throwArg) {
|
if (scope->function && scope->function->isThrow && !scope->function->throwArg) {
|
||||||
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (tok->str() != "throw") {
|
if (tok->str() == "throw") {
|
||||||
nothrowThrowError(tok);
|
nothrowThrowError(tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,12 +317,20 @@ private:
|
||||||
"void func3() noexcept(false) { throw 1; }\n");
|
"void func3() noexcept(false) { throw 1; }\n");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Exception thrown in noexcept function.\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());
|
"[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() {
|
void nothrowThrow() {
|
||||||
check("void func1() throw() { throw 1; }\n"
|
check("void func1() throw() { throw 1; }\n"
|
||||||
"void func2() throw(int) { throw 1; }\n");
|
"void func2() throw(int) { throw 1; }\n");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Exception thrown in throw() function.\n", errout.str());
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue