DuplicateBranch: Made warning inconclusive since it's in most cases noise

This commit is contained in:
Daniel Marjamäki 2014-02-16 11:04:27 +01:00
parent 23efc68dd7
commit fdcb325d70
2 changed files with 16 additions and 8 deletions

View File

@ -2574,7 +2574,15 @@ void CheckOther::duplicateIfError(const Token *tok1, const Token *tok2)
//-----------------------------------------------------------------------------
void CheckOther::checkDuplicateBranch()
{
if (!_settings->isEnabled("style"))
// This is inconclusive since in practice most warnings are noise:
// * There can be unfixed low-priority todos. The code is fine as it
// is but it could be possible to enhance it. Writing a warning
// here is noise since the code is fine (see cppcheck, abiword, ..)
// * There can be overspecified code so some conditions can't be true
// and their conditional code is a duplicate of the condition that
// is always true just in case it would be false. See for instance
// abiword.
if (!_settings->isEnabled("style") || !_settings->inconclusive)
return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
@ -2621,7 +2629,7 @@ void CheckOther::duplicateBranchError(const Token *tok1, const Token *tok2)
reportError(toks, Severity::style, "duplicateBranch", "Found duplicate branches for 'if' and 'else'.\n"
"Finding the same code in an 'if' and related 'else' branch is suspicious and "
"might indicate a cut and paste or logic error. Please examine this code "
"carefully to determine if it is correct.");
"carefully to determine if it is correct.", true);
}

View File

@ -4512,7 +4512,7 @@ private:
" else\n"
" b = 1;\n"
"}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout.str());
check("void f(int a, int &b) {\n"
" if (a) {\n"
@ -4523,7 +4523,7 @@ private:
" } else\n"
" b = 1;\n"
"}");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout.str());
check("void f(int a, int &b) {\n"
" if (a == 1)\n"
@ -4535,7 +4535,7 @@ private:
" b = 2;\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:5]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout.str());
check("int f(int signed, unsigned char value) {\n"
" int ret;\n"
@ -4561,7 +4561,7 @@ private:
" else\n"
" __asm__(\"mov ax, bx\");\n"
"}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout.str());
}
void duplicateBranch1() {
@ -4575,7 +4575,7 @@ private:
" else\n"
" frac = front/(front-back);\n"
"}");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout.str());
check("void f()\n"
"{\n"
@ -4584,7 +4584,7 @@ private:
" else\n"
" frac = front/((front-back));\n"
"}");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout.str());
}
void duplicateBranch2() {