Don't show inconclusive message redundantCopyLocalConst if --inconclusive is not set.

Ran AStyle
This commit is contained in:
PKEuS 2014-09-11 19:45:52 +02:00
parent 87e6a3501a
commit fb0d145b34
4 changed files with 21 additions and 17 deletions

View File

@ -2574,7 +2574,7 @@ static bool constructorTakesReference(const Scope * const classScope)
//---------------------------------------------------------------------------
void CheckOther::checkRedundantCopy()
{
if (!_settings->isEnabled("performance") || _tokenizer->isC())
if (!_settings->isEnabled("performance") || _tokenizer->isC() || !_settings->inconclusive)
return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();

View File

@ -219,7 +219,7 @@ void CheckType::checkSignConversion()
{
if (!_settings->isEnabled("warning"))
return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
@ -232,7 +232,7 @@ void CheckType::checkSignConversion()
char sign = 0;
if (!astGetSizeSign(_settings, tok, &size, &sign))
continue;
if (sign != 'u')
continue;
@ -249,7 +249,7 @@ void CheckType::checkSignConversion()
const Variable *var = tok1->variable();
if (var && tok1->getValueLE(-1,_settings)) {
bool signedvar = false;
for (const Token *type = var->typeStartToken();;type = type->next()) {
for (const Token *type = var->typeStartToken();; type = type->next()) {
if (type->isSigned()) {
signedvar = true;
break;
@ -272,7 +272,7 @@ void CheckType::checkSignConversion()
void CheckType::signConversionError(const Token *tok)
{
const std::string varname(tok ? tok->str() : "var");
reportError(tok,
Severity::warning,
"signConversion",

View File

@ -62,7 +62,7 @@ public:
/** @brief %Check for integer overflow */
void checkIntegerOverflow();
/** @brief %Check for dangerous sign conversion */
void checkSignConversion();

View File

@ -5231,12 +5231,13 @@ private:
ASSERT_EQUALS("", errout.str());
}
void check_redundant_copy(const char code[]) {
void check_redundant_copy(const char code[], bool inconclusive = true) {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.addEnabled("performance");
settings.inconclusive = inconclusive;
// Tokenize..
Tokenizer tokenizer(&settings, this);
@ -5332,17 +5333,20 @@ private:
ASSERT_EQUALS("", errout.str());
// #5618
check_redundant_copy("class Token {\n"
"public:\n"
" const std::string& str();\n"
"};\n"
"void simplifyArrayAccessSyntax() {\n"
" for (Token *tok = list.front(); tok; tok = tok->next()) {\n"
" const std::string temp = tok->str();\n"
" tok->str(tok->strAt(2));\n"
" }\n"
"}\n");
const char* code5618 = "class Token {\n"
"public:\n"
" const std::string& str();\n"
"};\n"
"void simplifyArrayAccessSyntax() {\n"
" for (Token *tok = list.front(); tok; tok = tok->next()) {\n"
" const std::string temp = tok->str();\n"
" tok->str(tok->strAt(2));\n"
" }\n"
"}";
check_redundant_copy(code5618);
TODO_ASSERT_EQUALS("", "[test.cpp:7]: (performance, inconclusive) Use const reference for 'temp' to avoid unnecessary data copying.\n", errout.str());
check_redundant_copy(code5618, false);
ASSERT_EQUALS("", errout.str());
// #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp
check_redundant_copy("typedef std::vector<char> X;\n"