Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,35 +273,36 @@ bool astIsContainerString(const Token* tok)
return container->stdStringLike;
}

static const Token* getContainerFunction(const Token* tok)
static std::pair<const Token*, const Library::Container*> getContainerFunction(const Token* tok, const Settings* settings)
{
if (!tok || !tok->valueType() || !tok->valueType()->container)
return nullptr;
const Library::Container* cont{};
if (!tok || !tok->valueType() || (!tok->valueType()->container && (!settings || !(cont = settings->library.detectContainerOrIterator(tok->valueType()->smartPointerTypeToken)))))
return {};
const Token* parent = tok->astParent();
if (Token::Match(parent, ". %name% (") && astIsLHS(tok)) {
return parent->next();
return { parent->next(), cont ? cont : tok->valueType()->container };
}
return nullptr;
return {};
}

Library::Container::Action astContainerAction(const Token* tok, const Token** ftok)
Library::Container::Action astContainerAction(const Token* tok, const Token** ftok, const Settings* settings)
{
const Token* ftok2 = getContainerFunction(tok);
const auto ftokCont = getContainerFunction(tok, settings);
if (ftok)
*ftok = ftok2;
if (!ftok2)
*ftok = ftokCont.first;
if (!ftokCont.first)
return Library::Container::Action::NO_ACTION;
return tok->valueType()->container->getAction(ftok2->str());
return ftokCont.second->getAction(ftokCont.first->str());
}

Library::Container::Yield astContainerYield(const Token* tok, const Token** ftok)
Library::Container::Yield astContainerYield(const Token* tok, const Token** ftok, const Settings* settings)
{
const Token* ftok2 = getContainerFunction(tok);
const auto ftokCont = getContainerFunction(tok, settings);
if (ftok)
*ftok = ftok2;
if (!ftok2)
*ftok = ftokCont.first;
if (!ftokCont.first)
return Library::Container::Yield::NO_YIELD;
return tok->valueType()->container->getYield(ftok2->str());
return ftokCont.second->getYield(ftokCont.first->str());
}

Library::Container::Yield astFunctionYield(const Token* tok, const Settings& settings, const Token** ftok)
Expand Down
4 changes: 2 additions & 2 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ bool astIsContainerView(const Token* tok);
bool astIsContainerOwned(const Token* tok);
bool astIsContainerString(const Token* tok);

Library::Container::Action astContainerAction(const Token* tok, const Token** ftok = nullptr);
Library::Container::Yield astContainerYield(const Token* tok, const Token** ftok = nullptr);
Library::Container::Action astContainerAction(const Token* tok, const Token** ftok = nullptr, const Settings* settings = nullptr);
Library::Container::Yield astContainerYield(const Token* tok, const Token** ftok = nullptr, const Settings* settings = nullptr);

Library::Container::Yield astFunctionYield(const Token* tok, const Settings& settings, const Token** ftok = nullptr);

Expand Down
4 changes: 2 additions & 2 deletions lib/checkfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,9 @@ void CheckFunctions::checkLibraryMatchFunctions()

if (Token::simpleMatch(tok->astParent(), ".")) {
const Token* contTok = tok->astParent()->astOperand1();
if (astContainerAction(contTok) != Library::Container::Action::NO_ACTION)
if (astContainerAction(contTok, nullptr, mSettings) != Library::Container::Action::NO_ACTION)
continue;
if (astContainerYield(contTok) != Library::Container::Yield::NO_YIELD)
if (astContainerYield(contTok, nullptr, mSettings) != Library::Container::Yield::NO_YIELD)
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,8 @@ const std::unordered_map<std::string, Library::Container>& Library::containers()

const Library::Container* Library::detectContainerInternal(const Token* const typeStart, DetectContainer detect, bool* isIterator, bool withoutStd) const
{
if (!typeStart)
return nullptr;
const Token* firstLinkedTok = nullptr;
for (const Token* tok = typeStart; tok && !tok->varId(); tok = tok->next()) {
if (!tok->link())
Expand Down
11 changes: 11 additions & 0 deletions test/testfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,17 @@ class TestFunctions : public TestFixture {
" void resize(size_t n) { std::vector<T>::resize(n); }\n"
"};\n", true, &s);
ASSERT_EQUALS("", errout_str());

check("struct P {\n" // #13105
" bool g(int i) const;\n"
" std::shared_ptr<std::map<int, int>> m;\n"
"};\n"
"bool P::g(int i) const {\n"
" auto it = m->find(i);\n"
" const bool b = it != m->end();\n"
" return b;\n"
"}\n", true, &s);
TODO_ASSERT_EQUALS("", "[test.cpp:6]: (debug) auto token with no type.\n", errout_str());
}

void checkUseStandardLibrary1() {
Expand Down