removed 'explicit constructors' check. see comments in pull request #51 for the reasons.
This commit is contained in:
parent
937a4497ca
commit
af7bf5c805
|
@ -90,14 +90,6 @@ void CheckClass::constructors()
|
|||
std::vector<Usage> usage(scope->varlist.size());
|
||||
|
||||
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
||||
// check for explicit
|
||||
if (func->type == Function::eConstructor) {
|
||||
if (!func->isExplicit && func->argumentList.size() == 1)
|
||||
explicitConstructorError(func->token, scope->className);
|
||||
if (func->isExplicit && func->argumentList.size() > 1)
|
||||
pointlessExplicitConstructorError(func->token, scope->className);
|
||||
}
|
||||
|
||||
if (!func->hasBody || !(func->type == Function::eConstructor ||
|
||||
func->type == Function::eCopyConstructor ||
|
||||
func->type == Function::eOperatorEqual))
|
||||
|
@ -523,32 +515,6 @@ void CheckClass::operatorEqVarError(const Token *tok, const std::string &classna
|
|||
reportError(tok, Severity::warning, "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'");
|
||||
}
|
||||
|
||||
void CheckClass::explicitConstructorError(const Token *tok, const std::string &className)
|
||||
{
|
||||
reportError(tok, Severity::style,
|
||||
"explicitConstructorError", "Constructor for '" +
|
||||
className + "' should be explicit.\n"
|
||||
"The single-argument constructor for '" + className + "' should "
|
||||
"be explicit as it can be used for automatic conversion. This is "
|
||||
"convenient but can also be a problem when automatic conversion "
|
||||
"creates new objects when you were not expecting it. Adding the "
|
||||
"explicit declaration to the constructor prevents it being called "
|
||||
"for implicit conversions.");
|
||||
}
|
||||
|
||||
void CheckClass::pointlessExplicitConstructorError(const Token *tok, const std::string &className)
|
||||
{
|
||||
reportError(tok, Severity::style,
|
||||
"pointlessExplicitConstructorError", "Constructor for '" +
|
||||
className + "' is marked explicit but"
|
||||
" takes more than one argument.\n"
|
||||
"The explicit keyword prevents constructor calls for implicit "
|
||||
"conversions, but it is only needed for single-argument "
|
||||
"constructors. The constructor for '" + className + "' takes "
|
||||
"more than one argument so is not affected by the explicit "
|
||||
"declaration.");
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// ClassCheck: Unused private functions
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -128,8 +128,6 @@ private:
|
|||
void checkConstError(const Token *tok, const std::string &classname, const std::string &funcname);
|
||||
void checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname);
|
||||
void initializerListError(const Token *tok1,const Token *tok2, const std::string & classname, const std::string &varname);
|
||||
void explicitConstructorError(const Token *tok, const std::string &className);
|
||||
void pointlessExplicitConstructorError(const Token *tok, const std::string &className);
|
||||
|
||||
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) {
|
||||
CheckClass c(0, settings, errorLogger);
|
||||
|
@ -145,8 +143,6 @@ private:
|
|||
c.operatorEqToSelfError(0);
|
||||
c.checkConstError(0, "class", "function");
|
||||
c.initializerListError(0, 0, "class", "variable");
|
||||
c.explicitConstructorError(0, "classname");
|
||||
c.pointlessExplicitConstructorError(0, "classname");
|
||||
}
|
||||
|
||||
std::string myName() const {
|
||||
|
@ -162,8 +158,7 @@ private:
|
|||
"* Are there unused private functions\n"
|
||||
"* 'operator=' should return reference to self\n"
|
||||
"* 'operator=' should check for assignment to self\n"
|
||||
"* Constness for member functions\n"
|
||||
"* explicit should / shouldn't be used\n";
|
||||
"* Constness for member functions\n";
|
||||
}
|
||||
|
||||
// operatorEqRetRefThis helper function
|
||||
|
|
|
@ -81,7 +81,6 @@ private:
|
|||
TEST_CASE(initvar_destructor); // No variables need to be initialized in a destructor
|
||||
|
||||
TEST_CASE(operatorEqSTL);
|
||||
TEST_CASE(explicit_constructor);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1044,21 +1043,6 @@ private:
|
|||
"{ }", true);
|
||||
ASSERT_EQUALS("[test.cpp:13]: (warning) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n", errout.str());
|
||||
}
|
||||
|
||||
void explicit_constructor() {
|
||||
check("class Fred\n"
|
||||
"{\n"
|
||||
" Fred(int i);\n"
|
||||
"};\n"
|
||||
"\n", true);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Constructor for 'Fred' should be explicit.\n", errout.str());
|
||||
check("class Fred\n"
|
||||
"{\n"
|
||||
" explicit Fred(int a, int b);\n"
|
||||
"};\n"
|
||||
"\n", true);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Constructor for 'Fred' is marked explicit but takes more than one argument.\n", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestConstructors)
|
||||
|
|
Loading…
Reference in New Issue