CheckStructMemberUsage: Added more cases

This commit is contained in:
Daniel Marjamäki 2008-05-10 06:48:37 +00:00
parent 219d82e180
commit 58b1b5f101
2 changed files with 45 additions and 1 deletions

View File

@ -756,8 +756,14 @@ void CheckStructMemberUsage()
if (structname && Match(tok, "[{;]")) if (structname && Match(tok, "[{;]"))
{ {
const char *varname = 0; const char *varname = 0;
if (Match(tok->next, "%type% %var% ;")) if (Match(tok->next, "%type% %var% [;[]"))
varname = getstr( tok, 2 ); varname = getstr( tok, 2 );
else if (Match(tok->next, "%type% %type% %var% [;[]"))
varname = getstr( tok, 2 );
else if (Match(tok->next, "%type% * %var% [;[]"))
varname = getstr( tok, 3 );
else if (Match(tok->next, "%type% %type% * %var% [;[]"))
varname = getstr( tok, 4 );
else else
continue; continue;

View File

@ -935,6 +935,44 @@ static void unused_struct_member()
__LINE__, __LINE__,
"struct abc {int i;};", "struct abc {int i;};",
"[test.cpp:1]: struct member 'abc::i' is never read\n" ); "[test.cpp:1]: struct member 'abc::i' is never read\n" );
check( CheckStructMemberUsage,
__LINE__,
"struct abc {unsigned int i;};",
"[test.cpp:1]: struct member 'abc::i' is never read\n" );
check( CheckStructMemberUsage,
__LINE__,
"struct abc {int *i;};",
"[test.cpp:1]: struct member 'abc::i' is never read\n" );
check( CheckStructMemberUsage,
__LINE__,
"struct abc {unsigned int *i;};",
"[test.cpp:1]: struct member 'abc::i' is never read\n" );
check( CheckStructMemberUsage,
__LINE__,
"struct abc {int i[10];};",
"[test.cpp:1]: struct member 'abc::i' is never read\n" );
check( CheckStructMemberUsage,
__LINE__,
"struct abc {unsigned int i[10];};",
"[test.cpp:1]: struct member 'abc::i' is never read\n" );
check( CheckStructMemberUsage,
__LINE__,
"struct abc {int *i[10];};",
"[test.cpp:1]: struct member 'abc::i' is never read\n" );
check( CheckStructMemberUsage,
__LINE__,
"struct abc {unsigned int *i[10];};",
"[test.cpp:1]: struct member 'abc::i' is never read\n" );
} }