Bailout for duplicateBranch check if branches are empty (#5354)

This commit is contained in:
PKEuS 2014-09-01 10:19:14 +02:00
parent e35329aba3
commit 353a9e9a64
2 changed files with 11 additions and 1 deletions

View File

@ -2021,7 +2021,7 @@ void CheckOther::checkDuplicateBranch()
std::string branch2 = scope->classEnd->tokAt(3)->stringifyList(scope->classEnd->linkAt(2));
// check for duplicates
if (branch1 == branch2)
if (!branch1.empty() && branch1 == branch2)
duplicateBranchError(scope->classDef, scope->classEnd->next());
}
}

View File

@ -3759,6 +3759,16 @@ private:
" frac = front/((front-back));\n"
"}");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout.str());
// No message about empty branches (#5354)
check("void f()\n"
"{\n"
" if (front < 0)\n"
" {}\n"
" else\n"
" {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void duplicateBranch2() {