Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12208 FN constParameterReference with nested struct/class #5685

Merged
merged 3 commits into from
Nov 20, 2023
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
7 changes: 5 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5867,8 +5867,11 @@ const Function* SymbolDatabase::findFunction(const Token* const tok) const
if (tok1)
tok1 = tok1->tokAt(2);

if (currScope && tok1)
return currScope->findFunction(tok1);
if (currScope && tok1) {
const Function* func = currScope->findFunction(tok1);
if (func)
return func;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
#include <unordered_set>
#include <vector>

static void bailoutInternal(const std::string& type, TokenList &tokenlist, ErrorLogger *errorLogger, const Token *tok, const std::string &what, const std::string &file, int line, std::string function)
static void bailoutInternal(const std::string& type, const TokenList &tokenlist, ErrorLogger *errorLogger, const Token *tok, const std::string &what, const std::string &file, int line, std::string function)
{
if (function.find("operator") != std::string::npos)
function = "(valueFlow)";
Expand Down Expand Up @@ -4011,7 +4011,7 @@ struct LifetimeStore {
}
}

static LifetimeStore fromFunctionArg(const Function * f, const Token *tok, const Variable *var, TokenList &tokenlist, const Settings* settings, ErrorLogger *errorLogger) {
static LifetimeStore fromFunctionArg(const Function * f, const Token *tok, const Variable *var, const TokenList &tokenlist, const Settings* settings, ErrorLogger *errorLogger) {
if (!var)
return LifetimeStore{};
if (!var->isArgument())
Expand Down Expand Up @@ -7038,7 +7038,7 @@ static void valueFlowForLoopSimplify(Token* const bodyStart,
const Token* expr,
bool globalvar,
const MathLib::bigint value,
TokenList& tokenlist,
const TokenList& tokenlist,
ErrorLogger* errorLogger,
const Settings* settings)
{
Expand Down
16 changes: 16 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(findFunction50); // #11904 - method with same name and arguments in derived class
TEST_CASE(findFunction51); // #11975 - method with same name in derived class
TEST_CASE(findFunction52);
TEST_CASE(findFunction53);
TEST_CASE(findFunctionContainer);
TEST_CASE(findFunctionExternC);
TEST_CASE(findFunctionGlobalScope); // ::foo
Expand Down Expand Up @@ -7671,6 +7672,21 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(g->function()->tokenDef->linenr() == 1);
}

void findFunction53() {
GET_SYMBOL_DB("namespace N {\n" // #12208
" struct S {\n"
" S(const int*);\n"
" };\n"
"}\n"
"void f(int& r) {\n"
" N::S(&r);\n"
"}\n");
const Token* S = Token::findsimplematch(tokenizer.tokens(), "S ( &");
ASSERT(S->function() && S->function()->tokenDef);
ASSERT(S->function()->tokenDef->linenr() == 3);
ASSERT(S->function()->isConstructor());
}

void findFunctionContainer() {
{
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
Expand Down
Loading