Fixed #5707 (false negative: unreachable code is not detected (code after return))

This commit is contained in:
Frank Zingsheim 2014-04-23 07:58:43 +02:00 committed by Daniel Marjamäki
parent 3c5cf299e3
commit 87354bf9d2
2 changed files with 12 additions and 0 deletions

View File

@ -1619,6 +1619,7 @@ void CheckOther::checkUnreachableCode()
if (!tok)
break;
tok = tok->previous(); // Will be advanced again by for loop
}
}
}

View File

@ -3079,6 +3079,17 @@ private:
"}", 0, false, false, false, false);
ASSERT_EQUALS("[test.cpp:4]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str());
// #5707
check("extern int i,j\n"
"int foo() {\n"
" switch(i) {\n"
" default: j=1; break;\n"
" }\n"
" return 0;\n"
" j=2;\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("[test.cpp:7]: (style) Statements following return, break, continue, goto or throw will never be executed.\n", errout.str());
check("int foo() {\n"
" return 0;\n"
" label:\n"