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

Method redundantCondition

lib/checkstl.cpp:1825–1856  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1823}
1824
1825void CheckStlImpl::redundantCondition()
1826{
1827 if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("redundantIfRemove"))
1828 return;
1829
1830 logChecker("CheckStl::redundantCondition"); // style
1831
1832 const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
1833
1834 for (const Scope &scope : symbolDatabase->scopeList) {
1835 if (scope.type != ScopeType::eIf)
1836 continue;
1837
1838 const Token* tok = scope.classDef->tokAt(2);
1839 if (!Token::Match(tok, "%name% . find ( %any% ) != %name% . end|rend|cend|crend ( ) ) { %name% . remove|erase ( %any% ) ;"))
1840 continue;
1841
1842 // Get tokens for the fields %name% and %any%
1843 const Token *var1 = tok;
1844 const Token *any1 = var1->tokAt(4);
1845 const Token *var2 = any1->tokAt(3);
1846 const Token *var3 = var2->tokAt(7);
1847 const Token *any2 = var3->tokAt(4);
1848
1849 // Check if all the "%name%" fields are the same and if all the "%any%" are the same..
1850 if (var1->str() == var2->str() &&
1851 var2->str() == var3->str() &&
1852 any1->str() == any2->str()) {
1853 redundantIfRemoveError(tok);
1854 }
1855 }
1856}
1857
1858void CheckStlImpl::redundantIfRemoveError(const Token *tok)
1859{

Callers 1

runChecksMethod · 0.80

Calls 4

isPremiumEnabledMethod · 0.80
isEnabledMethod · 0.45
tokAtMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected