Fixed #1669 (Still seeing 'possible style' warnings in 1.43)
This commit is contained in:
parent
5d01047ae4
commit
84c3ec9c4c
|
@ -1216,7 +1216,7 @@ static bool hasMultipleInheritanceGlobal(const Token * start, const std::string
|
||||||
|
|
||||||
void CheckClass::operatorEqToSelf()
|
void CheckClass::operatorEqToSelf()
|
||||||
{
|
{
|
||||||
if (!_settings->_checkCodingStyle || !_settings->inconclusive)
|
if (!_settings->_checkCodingStyle)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const Token *tok2 = _tokenizer->tokens();
|
const Token *tok2 = _tokenizer->tokens();
|
||||||
|
@ -1994,7 +1994,7 @@ void CheckClass::uninitVarError(const Token *tok, const std::string &classname,
|
||||||
|
|
||||||
void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname)
|
void CheckClass::operatorEqVarError(const Token *tok, const std::string &classname, const std::string &varname)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::possibleStyle, "operatorEqVarError", "Member variable '" + classname + "::" + varname + "' is not assigned a value in '" + classname + "::operator=" + "'");
|
reportError(tok, Severity::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)
|
void CheckClass::unusedPrivateFunctionError(const Token *tok, const std::string &classname, const std::string &funcname)
|
||||||
|
@ -2029,5 +2029,5 @@ void CheckClass::operatorEqRetRefThisError(const Token *tok)
|
||||||
|
|
||||||
void CheckClass::operatorEqToSelfError(const Token *tok)
|
void CheckClass::operatorEqToSelfError(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::possibleStyle, "operatorEqToSelf", "'operator=' should check for assignment to self");
|
reportError(tok, Severity::style, "operatorEqToSelf", "'operator=' should check for assignment to self");
|
||||||
}
|
}
|
||||||
|
|
|
@ -479,7 +479,7 @@ private:
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
|
||||||
// this test has an assignment test but doesn't need it
|
// this test has an assignment test but doesn't need it
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
|
@ -534,7 +534,7 @@ private:
|
||||||
" s = strdup(a.s);\n"
|
" s = strdup(a.s);\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
|
||||||
// ticket #1224
|
// ticket #1224
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
|
@ -621,7 +621,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
|
||||||
// this test has an assignment test but doesn't need it
|
// this test has an assignment test but doesn't need it
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
|
@ -692,7 +692,7 @@ private:
|
||||||
" s = strdup(b.s);\n"
|
" s = strdup(b.s);\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\n");
|
" }\n");
|
||||||
ASSERT_EQUALS("[test.cpp:11]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:11]: (style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void operatorEqToSelf3()
|
void operatorEqToSelf3()
|
||||||
|
@ -1118,7 +1118,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" char * data;\n"
|
" char * data;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -1135,7 +1135,7 @@ private:
|
||||||
" strcpy(data, a.data);\n"
|
" strcpy(data, a.data);\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -1151,7 +1151,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" char * data;\n"
|
" char * data;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqToSelf(
|
checkOpertorEqToSelf(
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -1168,7 +1168,7 @@ private:
|
||||||
" *data = *a.data;\n"
|
" *data = *a.data;\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (possible style) 'operator=' should check for assignment to self\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should check for assignment to self\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that base classes have virtual destructors
|
// Check that base classes have virtual destructors
|
||||||
|
@ -1763,8 +1763,13 @@ private:
|
||||||
" Foo(int _i) { }\n"
|
" Foo(int _i) { }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
|
|
||||||
|
// actual results - "possible style" for both messages
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n"
|
ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n"
|
||||||
"[test.cpp:7]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
|
"[test.cpp:7]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
|
||||||
|
|
||||||
|
// wanted results - "style" for the public constructor
|
||||||
|
TODO_ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable not initialized in the constructor 'Foo::foo'\n"
|
||||||
|
"[test.cpp:7]: (style) Member variable not initialized in the constructor 'Foo::foo'\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -390,7 +390,7 @@ private:
|
||||||
" void operator=(const Fred &fred) { }\n"
|
" void operator=(const Fred &fred) { }\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (possible style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str());
|
||||||
|
|
||||||
check("struct Fred\n"
|
check("struct Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -398,7 +398,7 @@ private:
|
||||||
" void operator=(const Fred &fred) { }\n"
|
" void operator=(const Fred &fred) { }\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void initvar_operator_eq3()
|
void initvar_operator_eq3()
|
||||||
|
@ -706,7 +706,7 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
"void Fred::operator=(const Fred &f)\n"
|
"void Fred::operator=(const Fred &f)\n"
|
||||||
"{ }", true);
|
"{ }", true);
|
||||||
ASSERT_EQUALS("[test.cpp:13]: (possible style) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:13]: (style) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue