| 3268 | } |
| 3269 | |
| 3270 | void CheckStlImpl::knownEmptyContainer() |
| 3271 | { |
| 3272 | if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("knownEmptyContainer")) |
| 3273 | return; |
| 3274 | logChecker("CheckStl::knownEmptyContainer"); // style |
| 3275 | for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) { |
| 3276 | for (const Token *tok = function->bodyStart; tok != function->bodyEnd; tok = tok->next()) { |
| 3277 | |
| 3278 | if (!Token::Match(tok, "%name% ( !!)")) |
| 3279 | continue; |
| 3280 | |
| 3281 | // Parse range-based for loop |
| 3282 | if (tok->str() == "for") { |
| 3283 | if (!Token::simpleMatch(tok->linkAt(1), ") {")) |
| 3284 | continue; |
| 3285 | const Token *splitTok = tok->next()->astOperand2(); |
| 3286 | if (!Token::simpleMatch(splitTok, ":")) |
| 3287 | continue; |
| 3288 | const Token* contTok = splitTok->astOperand2(); |
| 3289 | if (!isKnownEmptyContainer(contTok)) |
| 3290 | continue; |
| 3291 | knownEmptyContainerError(contTok, ""); |
| 3292 | } else { |
| 3293 | const std::vector<const Token *> args = getArguments(tok); |
| 3294 | if (args.empty()) |
| 3295 | continue; |
| 3296 | |
| 3297 | for (int argnr = 1; argnr <= args.size(); ++argnr) { |
| 3298 | const Library::ArgumentChecks::IteratorInfo *i = mSettings.library.getArgIteratorInfo(tok, argnr); |
| 3299 | if (!i) |
| 3300 | continue; |
| 3301 | const Token * const argTok = args[argnr - 1]; |
| 3302 | if (!isKnownEmptyContainer(argTok)) |
| 3303 | continue; |
| 3304 | knownEmptyContainerError(argTok, tok->str()); |
| 3305 | break; |
| 3306 | |
| 3307 | } |
| 3308 | } |
| 3309 | } |
| 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | void CheckStlImpl::eraseIteratorOutOfBoundsError(const Token *ftok, const Token* itertok, const ValueFlow::Value* val) |
| 3314 | { |
no test coverage detected