diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index ac6fc8707..4f8a6b948 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -270,7 +270,9 @@ void CheckExceptionSafety::unhandledExceptionSpecification() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; // only check functions without exception epecification - if (scope->function && !scope->function->isThrow) { + if (scope->function && !scope->function->isThrow && + scope->className != "main" && scope->className != "wmain" && + scope->className != "_tmain" && scope->className != "WinMain") { for (const Token *tok = scope->function->functionScope->classStart->next(); tok != scope->function->functionScope->classEnd; tok = tok->next()) { if (tok->str() == "try") { diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 401808197..da419b13c 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -44,7 +44,8 @@ private: TEST_CASE(catchExceptionByValue); TEST_CASE(noexceptThrow); TEST_CASE(nothrowThrow); - TEST_CASE(unhandledExceptionSpecification); // #4800 + TEST_CASE(unhandledExceptionSpecification1); // #4800 + TEST_CASE(unhandledExceptionSpecification2); TEST_CASE(nothrowAttributeThrow); TEST_CASE(nothrowAttributeThrow2); // #5703 } @@ -344,7 +345,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void unhandledExceptionSpecification() { // #4800 + void unhandledExceptionSpecification1() { // #4800 check("void myThrowingFoo() throw(MyException) {\n" " throw MyException();\n" "}\n" @@ -359,6 +360,15 @@ private: ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:1]: (warning) Unhandled exception specification when calling function myThrowingFoo().\n", errout.str()); } + void unhandledExceptionSpecification2() { + check("void f() const throw (std::runtime_error);\n" + "int main()\n" + "{\n" + " f();\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void nothrowAttributeThrow() { check("void func1() throw(int) { throw 1; }\n" "void func2() __attribute((nothrow)); void func1() { throw 1; }\n"