Fixed #5563 (add __attribute__((destructor)) and improve __attribute__((constructor)) support)

This commit is contained in:
Robert Reif 2014-03-14 18:17:21 +01:00 committed by Daniel Marjamäki
parent b2708987c3
commit e26bd5b99c
2 changed files with 41 additions and 2 deletions

View File

@ -64,8 +64,8 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
if (Token::Match(tok->previous(), ")|const") || funcname == 0)
continue;
// Don't warn about functions that are marked by __attribute__((constructor))
if (tok->isAttributeConstructor() || funcname->isAttributeConstructor())
// Don't warn about functions that are marked by __attribute__((constructor)) or __attribute__((destructor))
if (funcname->isAttributeConstructor() || funcname->isAttributeDestructor())
continue;
tok = funcname->linkAt(1);

View File

@ -238,6 +238,45 @@ private:
void attribute() { // #3471 - FP __attribute__((constructor))
check("void __attribute__((constructor)) f() {}");
ASSERT_EQUALS("", errout.str());
check("void __attribute__((constructor(1000))) f() {}");
ASSERT_EQUALS("", errout.str());
check("void __attribute__((destructor)) f() {}");
ASSERT_EQUALS("", errout.str());
check("void __attribute__((destructor(1000))) f() {}");
ASSERT_EQUALS("", errout.str());
// alternate syntax
check("__attribute__((constructor)) void f() {}");
ASSERT_EQUALS("", errout.str());
check("__attribute__((constructor(1000))) void f() {}");
ASSERT_EQUALS("", errout.str());
check("__attribute__((destructor)) void f() {}");
ASSERT_EQUALS("", errout.str());
check("__attribute__((destructor(1000))) void f() {}");
ASSERT_EQUALS("", errout.str());
// alternate syntax
check("void f() __attribute__((constructor));\n"
"void f() { }");
ASSERT_EQUALS("", errout.str());
check("void f() __attribute__((constructor(1000)));\n"
"void f() { }");
ASSERT_EQUALS("", errout.str());
check("void f() __attribute__((destructor));\n"
"void f() { }");
ASSERT_EQUALS("", errout.str());
check("void f() __attribute__((destructor(1000)));\n"
"void f() { }");
ASSERT_EQUALS("", errout.str());
}