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
4 changes: 3 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ void SymbolDatabase::createSymbolDatabaseIncompleteVars()
}
}

// cppcheck-suppress functionConst - has side effects
void SymbolDatabase::createSymbolDatabaseEscapeFunctions()
{
for (const Scope& scope : scopeList) {
Expand Down Expand Up @@ -8574,7 +8575,8 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
return ValueType::MatchResult::NOMATCH; // TODO
}
if (call->pointer > 0) {
if ((call->constness | func->constness) != func->constness)
const unsigned int mask = (1U << call->pointer) - 1;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is to mask off the constness of the pointer itself.. the constness for what it points at should be kept.
const int * => const int *
const int * const => const int *
const int * * const => const int * *
int * const * const => int * const *

if (((call->constness | func->constness) & mask) != (func->constness & mask))
return ValueType::MatchResult::NOMATCH;
if ((call->volatileness | func->volatileness) != func->volatileness)
return ValueType::MatchResult::NOMATCH;
Expand Down
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5507,7 +5507,7 @@ static void valueFlowForLoopSimplifyAfter(Token* fortok, nonneg int varid, const
}
}

static void valueFlowForLoop(TokenList &tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
static void valueFlowForLoop(const TokenList &tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
{
for (const Scope &scope : symboldatabase.scopeList) {
if (scope.type != ScopeType::eFor)
Expand Down
17 changes: 17 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(findFunction59);
TEST_CASE(findFunction60);
TEST_CASE(findFunction61);
TEST_CASE(findFunction62); // #14272 - pointer passed to function is const
TEST_CASE(findFunctionRef1);
TEST_CASE(findFunctionRef2); // #13328
TEST_CASE(findFunctionContainer);
Expand Down Expand Up @@ -8694,6 +8695,22 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(fun && !fun->function());
}

void findFunction62() { // #14272
GET_SYMBOL_DB("class Token {\n"
" std::string stringifyList(const Token* end, bool attributes = true) const;\n"
" std::string stringifyList(bool varid = false) const;\n"
"};\n"
"\n"
"void foo(const Token * const tokIf) {\n"
" tokIf->stringifyList(tokIf);\n"
"}\n");
const Token* functionCall = Token::findsimplematch(tokenizer.tokens(), "stringifyList ( tokIf )");
ASSERT(functionCall);
ASSERT(functionCall->function());
ASSERT(functionCall->function()->token);
ASSERT_EQUALS(2, functionCall->function()->token->linenr());
}

void findFunctionRef1() {
GET_SYMBOL_DB("struct X {\n"
" const std::vector<int> getInts() const & { return mInts; }\n"
Expand Down
Loading