diff --git a/lib/library.cpp b/lib/library.cpp index 3582ede82bb..a57115ac5b6 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1715,6 +1715,8 @@ bool Library::isnoreturn(const Token *ftok) const { if (ftok->function() && ftok->function()->isAttributeNoreturn()) return true; + if (ftok->variable() && ftok->variable()->nameToken()->isAttributeNoreturn()) + return true; if (isNotLibraryFunction(ftok)) { if (Token::simpleMatch(ftok->astParent(), ".")) { const Token* contTok = ftok->astParent()->astOperand1(); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 06266aa2dd8..9e50ddfee9d 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -131,6 +131,7 @@ class TestLeakAutoVar : public TestFixture { TEST_CASE(exit1); TEST_CASE(exit2); TEST_CASE(exit3); + TEST_CASE(exit4); // handling function calls TEST_CASE(functioncall1); @@ -1784,6 +1785,19 @@ class TestLeakAutoVar : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void exit4() { + check("void __attribute__((__noreturn__)) (*func_notret)(void);\n" + "int main(int argc) {\n" + " void* ptr = malloc(1000);\n" + " if (argc == 1) {\n" + " free(ptr);\n" + " func_notret();\n" + " }\n" + " free(ptr);\n" + "}"); + ASSERT_EQUALS("", errout_str()); + } + void functioncall1() { check("void f(struct S *p) {\n" " p->x = malloc(10);\n"