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() void CheckOther::checkRedundantCopy()
{ {
if (!_settings->isEnabled("performance") || _tokenizer->isC()) if (!_settings->isEnabled("performance") || _tokenizer->isC() || !_settings->inconclusive)
return; return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();

View File

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

View File

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

View File

@ -5231,12 +5231,13 @@ private:
ASSERT_EQUALS("", errout.str()); 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.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("performance"); settings.addEnabled("performance");
settings.inconclusive = inconclusive;
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
@ -5332,17 +5333,20 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #5618 // #5618
check_redundant_copy("class Token {\n" const char* code5618 = "class Token {\n"
"public:\n" "public:\n"
" const std::string& str();\n" " const std::string& str();\n"
"};\n" "};\n"
"void simplifyArrayAccessSyntax() {\n" "void simplifyArrayAccessSyntax() {\n"
" for (Token *tok = list.front(); tok; tok = tok->next()) {\n" " for (Token *tok = list.front(); tok; tok = tok->next()) {\n"
" const std::string temp = tok->str();\n" " const std::string temp = tok->str();\n"
" tok->str(tok->strAt(2));\n" " tok->str(tok->strAt(2));\n"
" }\n" " }\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()); 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 // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp
check_redundant_copy("typedef std::vector<char> X;\n" check_redundant_copy("typedef std::vector<char> X;\n"