diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 2919eb875..ba94c39a0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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()); } } diff --git a/test/testother.cpp b/test/testother.cpp index 42874ae89..e6e4bf588 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {