From 36e10124d013ba99c558a9bb95154c3e55bd1f51 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 20 Nov 2023 15:03:17 +0100 Subject: [PATCH 1/3] Fix #12208 FN constParameterReference with nested struct/class --- lib/symboldatabase.cpp | 7 +++++-- test/testsymboldatabase.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 5e9c9d24081..339ea640ee6 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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; + } } } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 13570130609..103716158a6 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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 @@ -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 v);\n" From 13a0574cd83b6f20d1c692486382abecda464735 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 20 Nov 2023 15:33:01 +0100 Subject: [PATCH 2/3] Add const --- lib/valueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index c1e6424362f..9da2928e6cb 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -127,7 +127,7 @@ #include #include -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)"; From 553a877e9ce45ec9d860211864e5496b0954b977 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 20 Nov 2023 16:37:25 +0100 Subject: [PATCH 3/3] Add const --- lib/valueflow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9da2928e6cb..3a375e3eef6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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()) @@ -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) {