Skip to content

Commit

Permalink
Add helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 5, 2024
1 parent b2bc09d commit d342842
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,14 @@ bool astIsIterator(const Token *tok)
return tok && tok->valueType() && tok->valueType()->type == ValueType::Type::ITERATOR;
}

const Library::Container* astIsContainer(const Token* tok) {
bool astIsContainer(const Token* tok) {
return getLibraryContainer(tok) != nullptr && !astIsIterator(tok);
}

bool astIsUniversalContainer(const Token* tok)
{
const Library::Container* container = getLibraryContainer(tok);
return container != nullptr && !astIsIterator(tok) ? container : nullptr;
return container && !container->stdStringLike && !astIsIterator(tok);
}

bool astIsContainerView(const Token* tok)
Expand Down
3 changes: 2 additions & 1 deletion lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ bool astIsUniqueSmartPointer(const Token* tok);

bool astIsIterator(const Token *tok);

const Library::Container* astIsContainer(const Token *tok);
bool astIsContainer(const Token *tok);
bool astIsUniversalContainer(const Token *tok);

bool astIsContainerView(const Token* tok);
bool astIsContainerOwned(const Token* tok);
Expand Down
3 changes: 1 addition & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4455,7 +4455,6 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList &tokenlist, ErrorLog
if (Token::Match(tok->astParent(), ". %name% (") && astIsRHS(tok))
memtok = tok->astParent()->astOperand1();
const int returnContainer = settings.library.returnValueContainer(tok);
const Library::Container* container{};
if (returnContainer >= 0) {
std::vector<const Token *> args = getArguments(tok);
for (int argnr = 1; argnr <= args.size(); ++argnr) {
Expand Down Expand Up @@ -4490,7 +4489,7 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList &tokenlist, ErrorLog
tok->next(), tokenlist, errorLogger, settings);
}
} else if (memtok && Token::Match(tok->astParent(), ". push_back|push_front|insert|push|assign") &&
(container = astIsContainer(memtok)) && !container->stdStringLike) {
astIsUniversalContainer(memtok)) {
std::vector<const Token *> args = getArguments(tok);
const std::size_t n = args.size();
if (n > 1 && Token::typeStr(args[n - 2]) == Token::typeStr(args[n - 1]) &&
Expand Down

0 comments on commit d342842

Please sign in to comment.