Tell if it's struct or union
This commit is contained in:
parent
a0b97d7676
commit
0b991f5560
|
@ -1252,16 +1252,17 @@ void CheckUnusedVar::checkStructMemberUsage()
|
|||
}
|
||||
}
|
||||
|
||||
if (! used) {
|
||||
unusedStructMemberError(tok->next(), structname, *varname);
|
||||
if (!used) {
|
||||
unusedStructMemberError(tok->next(), structname, *varname, tok->scope()->type == Scope::eUnion);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckUnusedVar::unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname)
|
||||
void CheckUnusedVar::unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname, bool isUnion)
|
||||
{
|
||||
reportError(tok, Severity::style, "unusedStructMember", "struct or union member '" + structname + "::" + varname + "' is never used.");
|
||||
const char* prefix = isUnion ? "union member '" : "struct member '";
|
||||
reportError(tok, Severity::style, "unusedStructMember", std::string(prefix) + structname + "::" + varname + "' is never used.");
|
||||
}
|
||||
|
||||
bool CheckUnusedVar::isRecordTypeWithoutSideEffects(const Type* type)
|
||||
|
|
|
@ -75,7 +75,7 @@ private:
|
|||
bool isEmptyType(const Type* type);
|
||||
|
||||
// Error messages..
|
||||
void unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname);
|
||||
void unusedStructMemberError(const Token *tok, const std::string &structname, const std::string &varname, bool isUnion = false);
|
||||
void unusedVariableError(const Token *tok, const std::string &varname);
|
||||
void allocatedButUnusedVariableError(const Token *tok, const std::string &varname);
|
||||
void unreadVariableError(const Token *tok, const std::string &varname);
|
||||
|
|
|
@ -208,9 +208,20 @@ private:
|
|||
" int b;\n"
|
||||
" int c;\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) struct or union member 'abc::a' is never used.\n"
|
||||
"[test.cpp:4]: (style) struct or union member 'abc::b' is never used.\n"
|
||||
"[test.cpp:5]: (style) struct or union member 'abc::c' is never used.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) struct member 'abc::a' is never used.\n"
|
||||
"[test.cpp:4]: (style) struct member 'abc::b' is never used.\n"
|
||||
"[test.cpp:5]: (style) struct member 'abc::c' is never used.\n", errout.str());
|
||||
|
||||
checkStructMemberUsage("union abc\n"
|
||||
"{\n"
|
||||
" int a;\n"
|
||||
" int b;\n"
|
||||
" int c;\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) union member 'abc::a' is never used.\n"
|
||||
"[test.cpp:4]: (style) union member 'abc::b' is never used.\n"
|
||||
"[test.cpp:5]: (style) union member 'abc::c' is never used.\n", errout.str());
|
||||
|
||||
}
|
||||
|
||||
void structmember2() {
|
||||
|
@ -418,7 +429,7 @@ private:
|
|||
"{\n"
|
||||
" ab.b = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) struct or union member 'AB::a' is never used.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) struct member 'AB::a' is never used.\n", errout.str());
|
||||
}
|
||||
|
||||
void functionVariableUsage(const char code[], const char filename[]="test.cpp") {
|
||||
|
|
Loading…
Reference in New Issue