diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index 4a93f05b4..fefdf7531 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -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); } } diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index aa22aea04..fa415b49f 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -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()); } };