Skip to content

Commit f8dc986

Browse files
authored
Fix issue 10202: FP: constParameter (#3202)
1 parent c8e661f commit f8dc986

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

‎lib/symboldatabase.cpp‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6830,20 +6830,27 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
68306830
return ValueType::MatchResult::UNKNOWN; // TODO
68316831
}
68326832

6833-
if (call->typeScope != nullptr || func->typeScope != nullptr)
6834-
return call->typeScope == func->typeScope ? ValueType::MatchResult::SAME : ValueType::MatchResult::NOMATCH;
6833+
if (call->typeScope != nullptr || func->typeScope != nullptr) {
6834+
if (call->typeScope != func->typeScope)
6835+
return ValueType::MatchResult::NOMATCH;
6836+
}
68356837

68366838
if (call->container != nullptr || func->container != nullptr) {
68376839
if (call->container != func->container)
68386840
return ValueType::MatchResult::NOMATCH;
68396841
}
68406842

6841-
else if (func->type < ValueType::Type::VOID || func->type == ValueType::Type::UNKNOWN_INT)
6842-
return ValueType::MatchResult::UNKNOWN;
6843+
if (func->typeScope != nullptr && func->container != nullptr) {
6844+
if (func->type < ValueType::Type::VOID || func->type == ValueType::Type::UNKNOWN_INT)
6845+
return ValueType::MatchResult::UNKNOWN;
6846+
}
68436847

68446848
if (call->isIntegral() && func->isIntegral() && call->sign != ValueType::Sign::UNKNOWN_SIGN && func->sign != ValueType::Sign::UNKNOWN_SIGN && call->sign != func->sign)
68456849
return ValueType::MatchResult::FALLBACK1;
68466850

6851+
if (func->reference != Reference::None && func->constness > call->constness)
6852+
return ValueType::MatchResult::FALLBACK1;
6853+
68476854
return ValueType::MatchResult::SAME;
68486855
}
68496856

‎test/testsymboldatabase.cpp‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ class TestSymbolDatabase: public TestFixture {
405405
TEST_CASE(findFunction38); // #10125
406406
TEST_CASE(findFunction39); // #10127
407407
TEST_CASE(findFunction40); // #10135
408+
TEST_CASE(findFunction41); // #10202
409+
TEST_CASE(findFunction42);
408410
TEST_CASE(findFunctionContainer);
409411
TEST_CASE(findFunctionExternC);
410412
TEST_CASE(findFunctionGlobalScope); // ::foo
@@ -6378,6 +6380,51 @@ class TestSymbolDatabase: public TestFixture {
63786380
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
63796381
}
63806382

6383+
void findFunction41() { // #10202
6384+
{
6385+
GET_SYMBOL_DB("struct A {};\n"
6386+
"const int* g(const A&);\n"
6387+
"int* g(A&);\n"
6388+
"void f(A& x) {\n"
6389+
" int* y = g(x);\n"
6390+
" *y = 0;\n"
6391+
"}\n");
6392+
ASSERT_EQUALS("", errout.str());
6393+
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "g ( x )");
6394+
ASSERT(functok);
6395+
ASSERT(functok->function());
6396+
ASSERT(functok->function()->name() == "g");
6397+
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
6398+
}
6399+
{
6400+
GET_SYMBOL_DB("struct A {};\n"
6401+
"const int* g(const A&);\n"
6402+
"int* g(A&);\n"
6403+
"void f(const A& x) {\n"
6404+
" int* y = g(x);\n"
6405+
" *y = 0;\n"
6406+
"}\n");
6407+
ASSERT_EQUALS("", errout.str());
6408+
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "g ( x )");
6409+
ASSERT(functok);
6410+
ASSERT(functok->function());
6411+
ASSERT(functok->function()->name() == "g");
6412+
ASSERT_EQUALS(2, functok->function()->tokenDef->linenr());
6413+
}
6414+
}
6415+
6416+
void findFunction42() {
6417+
GET_SYMBOL_DB("void a(const std::string &, const std::string &);\n"
6418+
"void a(long, long);\n"
6419+
"void b() { a(true, false); }\n");
6420+
ASSERT_EQUALS("", errout.str());
6421+
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "a ( true , false )");
6422+
ASSERT(functok);
6423+
ASSERT(functok->function());
6424+
ASSERT(functok->function()->name() == "a");
6425+
ASSERT_EQUALS(2, functok->function()->tokenDef->linenr());
6426+
}
6427+
63816428
void findFunctionContainer() {
63826429
{
63836430
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"

0 commit comments

Comments
 (0)