operator=: changed error message when variable is not assigned
This commit is contained in:
parent
14bdf1ee62
commit
ebee7928e2
|
@ -371,7 +371,10 @@ void CheckClass::CheckConstructors(const Token *tok1, struct VAR *varlist, const
|
|||
continue;
|
||||
|
||||
// It's non-static and it's not initialized => error
|
||||
uninitVarError(constructor_token, className, var->name);
|
||||
if (strcmp(funcname, "operator =") == 0)
|
||||
operatorEqVarError(constructor_token, className, var->name);
|
||||
else
|
||||
uninitVarError(constructor_token, className, var->name);
|
||||
}
|
||||
|
||||
for (struct VAR *var = varlist; var; var = var->next)
|
||||
|
@ -590,7 +593,7 @@ void CheckClass::operatorEq()
|
|||
const Token *tok = Token::findmatch(_tokenizer->tokens(), "void operator = (");
|
||||
if (tok)
|
||||
{
|
||||
operatorEqError(tok);
|
||||
operatorEqReturnError(tok);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -697,6 +700,11 @@ void CheckClass::uninitVarError(const Token *tok, const std::string &classname,
|
|||
reportError(tok, "style", "uninitVar", "Member variable not initialized in the constructor '" + classname + "::" + varname + "'");
|
||||
}
|
||||
|
||||
void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname)
|
||||
{
|
||||
reportError(tok, "all style", "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'");
|
||||
}
|
||||
|
||||
void CheckClass::unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname)
|
||||
{
|
||||
reportError(tok, "style", "unusedPrivateFunction", "Unused private function '" + classname + "::" + funcname + "'");
|
||||
|
@ -712,7 +720,7 @@ void CheckClass::memsetStructError(const Token *tok, const std::string &memfunc,
|
|||
reportError(tok, "error", "memsetStruct", "Using '" + memfunc + "' on struct that contains a 'std::" + classname + "'");
|
||||
}
|
||||
|
||||
void CheckClass::operatorEqError(const Token *tok)
|
||||
void CheckClass::operatorEqReturnError(const Token *tok)
|
||||
{
|
||||
reportError(tok, "style", "operatorEq", "'operator=' should return something");
|
||||
}
|
||||
|
|
|
@ -101,20 +101,22 @@ private:
|
|||
// Reporting errors..
|
||||
void noConstructorError(const Token *tok, const std::string &classname);
|
||||
void uninitVarError(const Token *tok, const std::string &classname, const std::string &varname);
|
||||
void operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname);
|
||||
void unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname);
|
||||
void memsetClassError(const Token *tok, const std::string &memfunc);
|
||||
void memsetStructError(const Token *tok, const std::string &memfunc, const std::string &classname);
|
||||
void operatorEqError(const Token *tok);
|
||||
void operatorEqReturnError(const Token *tok);
|
||||
void virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived);
|
||||
|
||||
void getErrorMessages()
|
||||
{
|
||||
noConstructorError(0, "classname");
|
||||
uninitVarError(0, "classname", "varname");
|
||||
operatorEqVarError(0, "classname", "");
|
||||
unusedPrivateFunctionError(0, "classname", "funcname");
|
||||
memsetClassError(0, "memfunc");
|
||||
memsetStructError(0, "memfunc", "classname");
|
||||
operatorEqError(0);
|
||||
operatorEqReturnError(0);
|
||||
virtualDestructorError(0, "Base", "Derived");
|
||||
}
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ private:
|
|||
" void operator=() { }\n"
|
||||
" int i;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS(std::string("[test.cpp:5]: (style) Member variable not initialized in the constructor 'Fred::i'\n"), errout.str());
|
||||
ASSERT_EQUALS(std::string("[test.cpp:5]: (all style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n"), errout.str());
|
||||
}
|
||||
|
||||
void initvar_operator_eq3()
|
||||
|
|
Loading…
Reference in New Issue