Bailout for duplicateBranch check if branches are empty (#5354)
This commit is contained in:
parent
e35329aba3
commit
353a9e9a64
|
@ -2021,7 +2021,7 @@ void CheckOther::checkDuplicateBranch()
|
||||||
std::string branch2 = scope->classEnd->tokAt(3)->stringifyList(scope->classEnd->linkAt(2));
|
std::string branch2 = scope->classEnd->tokAt(3)->stringifyList(scope->classEnd->linkAt(2));
|
||||||
|
|
||||||
// check for duplicates
|
// check for duplicates
|
||||||
if (branch1 == branch2)
|
if (!branch1.empty() && branch1 == branch2)
|
||||||
duplicateBranchError(scope->classDef, scope->classEnd->next());
|
duplicateBranchError(scope->classDef, scope->classEnd->next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3759,6 +3759,16 @@ private:
|
||||||
" frac = front/((front-back));\n"
|
" 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());
|
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() {
|
void duplicateBranch2() {
|
||||||
|
|
Loading…
Reference in New Issue