Classes: Static variables don't need to be initialized or assigned in constructors etc
http://apps.sourceforge.net/trac/cppcheck/ticket/307
This commit is contained in:
parent
2e61201c18
commit
bad464ae9b
|
@ -77,12 +77,14 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const Token *tok1,
|
||||||
|
|
||||||
// If next token contains a ":".. it is not part of a variable declaration
|
// If next token contains a ":".. it is not part of a variable declaration
|
||||||
if (next->str().find(":") != std::string::npos)
|
if (next->str().find(":") != std::string::npos)
|
||||||
{
|
continue;
|
||||||
|
|
||||||
}
|
// Variable declarations that start with "static" shall be ignored..
|
||||||
|
if (next->str() == "static")
|
||||||
|
continue;
|
||||||
|
|
||||||
// Is it a variable declaration?
|
// Is it a variable declaration?
|
||||||
else if (Token::Match(next, "%type% %var% ;"))
|
if (Token::Match(next, "%type% %var% ;"))
|
||||||
{
|
{
|
||||||
if (withClasses)
|
if (withClasses)
|
||||||
varname = next->strAt(1);
|
varname = next->strAt(1);
|
||||||
|
|
|
@ -70,6 +70,7 @@ private:
|
||||||
TEST_CASE(initvar_chained_assign); // BUG 2270433
|
TEST_CASE(initvar_chained_assign); // BUG 2270433
|
||||||
TEST_CASE(initvar_2constructors); // BUG 2270353
|
TEST_CASE(initvar_2constructors); // BUG 2270353
|
||||||
TEST_CASE(initvar_constvar);
|
TEST_CASE(initvar_constvar);
|
||||||
|
TEST_CASE(initvar_staticvar);
|
||||||
|
|
||||||
TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor
|
TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor
|
||||||
|
|
||||||
|
@ -314,6 +315,19 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void initvar_staticvar()
|
||||||
|
{
|
||||||
|
check("class Fred\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" Fred() { }\n"
|
||||||
|
" static void *p;\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void initvar_private_constructor()
|
void initvar_private_constructor()
|
||||||
{
|
{
|
||||||
check("class Fred\n"
|
check("class Fred\n"
|
||||||
|
|
Loading…
Reference in New Issue