Unhandled exceptions: Dont warn when there are unhandled exceptions in main() function. #5751

This commit is contained in:
Robert Reif 2014-05-01 13:41:01 +02:00 committed by Daniel Marjamäki
parent d2ebd718a9
commit f6aaf6cc0d
2 changed files with 15 additions and 3 deletions

View File

@ -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") {

View File

@ -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"