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

Method checkUnusedLabel

lib/checkother.cpp:3746–3767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3744}
3745
3746void CheckOtherImpl::checkUnusedLabel()
3747{
3748 if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.severity.isEnabled(Severity::warning) && !mSettings.isPremiumEnabled("unusedLabel"))
3749 return;
3750
3751 logChecker("CheckOther::checkUnusedLabel"); // style,warning
3752
3753 const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
3754 for (const Scope * scope : symbolDatabase->functionScopes) {
3755 const bool hasIfdef = mTokenizer->hasIfdef(scope->bodyStart, scope->bodyEnd);
3756 for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
3757 if (!tok->scope()->isExecutable())
3758 tok = tok->scope()->bodyEnd;
3759
3760 if (Token::Match(tok, "{|}|; %name% :") && !tok->tokAt(1)->isKeyword()) {
3761 const std::string tmp("goto " + tok->strAt(1));
3762 if (!Token::findsimplematch(scope->bodyStart->next(), tmp.c_str(), tmp.size(), scope->bodyEnd->previous()) && !tok->next()->isExpandedMacro())
3763 unusedLabelError(tok->next(), tok->next()->scope()->type == ScopeType::eSwitch, hasIfdef);
3764 }
3765 }
3766 }
3767}
3768
3769void CheckOtherImpl::unusedLabelError(const Token* tok, bool inSwitch, bool hasIfdef)
3770{

Callers 1

runChecksMethod · 0.80

Calls 9

findsimplematchFunction · 0.85
isPremiumEnabledMethod · 0.80
hasIfdefMethod · 0.80
nextMethod · 0.80
scopeMethod · 0.80
isEnabledMethod · 0.45
isKeywordMethod · 0.45
tokAtMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected