MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / isVardeclInSwitch

Function isVardeclInSwitch

lib/checkother.cpp:979–1000  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

977}
978
979static bool isVardeclInSwitch(const Token* tok)
980{
981 if (!tok)
982 return false;
983 if (!isNestedInSwitch(tok->scope()))
984 return false;
985 if (const Token* end = Token::findsimplematch(tok, ";")) {
986 for (const Token* tok2 = tok; tok2 != end; tok2 = tok2->next()) {
987 if (tok2->isKeyword() && tok2->str() == "case")
988 return false;
989 if (tok2->variable() && tok2->variable()->nameToken() == tok2) {
990 end = tok2->scope()->bodyEnd;
991 for (const Token* tok3 = tok2; tok3 != end; tok3 = tok3->next()) {
992 if (tok3->isKeyword())
993 return tok3->str() == "case";
994 }
995 return false;
996 }
997 }
998 }
999 return false;
1000}
1001
1002//---------------------------------------------------------------------------
1003// Find consecutive return, break, continue, goto or throw statements. e.g.:

Callers 1

checkUnreachableCodeMethod · 0.85

Calls 8

isNestedInSwitchFunction · 0.85
findsimplematchFunction · 0.85
scopeMethod · 0.80
nextMethod · 0.80
variableMethod · 0.80
isKeywordMethod · 0.45
strMethod · 0.45
nameTokenMethod · 0.45

Tested by

no test coverage detected