Skip to content

Commit f9521cf

Browse files
Fix #12208 FN constParameterReference with nested struct/class (#5685)
1 parent f444696 commit f9521cf

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5867,8 +5867,11 @@ const Function* SymbolDatabase::findFunction(const Token* const tok) const
58675867
if (tok1)
58685868
tok1 = tok1->tokAt(2);
58695869

5870-
if (currScope && tok1)
5871-
return currScope->findFunction(tok1);
5870+
if (currScope && tok1) {
5871+
const Function* func = currScope->findFunction(tok1);
5872+
if (func)
5873+
return func;
5874+
}
58725875
}
58735876
}
58745877

lib/valueflow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
#include <unordered_set>
128128
#include <vector>
129129

130-
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)
130+
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)
131131
{
132132
if (function.find("operator") != std::string::npos)
133133
function = "(valueFlow)";
@@ -4011,7 +4011,7 @@ struct LifetimeStore {
40114011
}
40124012
}
40134013

4014-
static LifetimeStore fromFunctionArg(const Function * f, const Token *tok, const Variable *var, TokenList &tokenlist, const Settings* settings, ErrorLogger *errorLogger) {
4014+
static LifetimeStore fromFunctionArg(const Function * f, const Token *tok, const Variable *var, const TokenList &tokenlist, const Settings* settings, ErrorLogger *errorLogger) {
40154015
if (!var)
40164016
return LifetimeStore{};
40174017
if (!var->isArgument())
@@ -7038,7 +7038,7 @@ static void valueFlowForLoopSimplify(Token* const bodyStart,
70387038
const Token* expr,
70397039
bool globalvar,
70407040
const MathLib::bigint value,
7041-
TokenList& tokenlist,
7041+
const TokenList& tokenlist,
70427042
ErrorLogger* errorLogger,
70437043
const Settings* settings)
70447044
{

test/testsymboldatabase.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ class TestSymbolDatabase : public TestFixture {
452452
TEST_CASE(findFunction50); // #11904 - method with same name and arguments in derived class
453453
TEST_CASE(findFunction51); // #11975 - method with same name in derived class
454454
TEST_CASE(findFunction52);
455+
TEST_CASE(findFunction53);
455456
TEST_CASE(findFunctionContainer);
456457
TEST_CASE(findFunctionExternC);
457458
TEST_CASE(findFunctionGlobalScope); // ::foo
@@ -7671,6 +7672,21 @@ class TestSymbolDatabase : public TestFixture {
76717672
ASSERT(g->function()->tokenDef->linenr() == 1);
76727673
}
76737674

7675+
void findFunction53() {
7676+
GET_SYMBOL_DB("namespace N {\n" // #12208
7677+
" struct S {\n"
7678+
" S(const int*);\n"
7679+
" };\n"
7680+
"}\n"
7681+
"void f(int& r) {\n"
7682+
" N::S(&r);\n"
7683+
"}\n");
7684+
const Token* S = Token::findsimplematch(tokenizer.tokens(), "S ( &");
7685+
ASSERT(S->function() && S->function()->tokenDef);
7686+
ASSERT(S->function()->tokenDef->linenr() == 3);
7687+
ASSERT(S->function()->isConstructor());
7688+
}
7689+
76747690
void findFunctionContainer() {
76757691
{
76767692
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"

0 commit comments

Comments
 (0)