Skip to content

Commit a62e032

Browse files
Fix #13125 checkLibraryFunction warning due to bad overload resolution (#6837)
1 parent fe03930 commit a62e032

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8281,9 +8281,16 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
82818281
if (pvt && funcVar->isArray() && !(funcVar->isStlType() && Token::simpleMatch(funcVar->typeStartToken(), "std :: array"))) { // std::array doesn't decay to a pointer
82828282
vt = *pvt;
82838283
if (vt.pointer == 0) // don't bump array of pointers
8284-
++vt.pointer;
8284+
vt.pointer = funcVar->dimensions().size();
82858285
pvt = &vt;
82868286
}
8287+
ValueType cvt;
8288+
if (call && callVar && callVar->isArray() && !(callVar->isStlType() && Token::simpleMatch(callVar->typeStartToken(), "std :: array"))) {
8289+
cvt = *call;
8290+
if (cvt.pointer == 0) // don't bump array of pointers
8291+
cvt.pointer = callVar->dimensions().size();
8292+
call = &cvt;
8293+
}
82878294
const ValueType::MatchResult res = ValueType::matchParameter(call, pvt);
82888295
if (callVar && ((res == ValueType::MatchResult::SAME && call->container) || res == ValueType::MatchResult::UNKNOWN)) {
82898296
const std::string type1 = getTypeString(callVar->typeStartToken());

test/testsymboldatabase.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ class TestSymbolDatabase : public TestFixture {
518518
TEST_CASE(findFunction52);
519519
TEST_CASE(findFunction53);
520520
TEST_CASE(findFunction54);
521-
TEST_CASE(findFunction55); // #31004
521+
TEST_CASE(findFunction55); // #13004
522+
TEST_CASE(findFunction56);
522523
TEST_CASE(findFunctionRef1);
523524
TEST_CASE(findFunctionContainer);
524525
TEST_CASE(findFunctionExternC);
@@ -8330,6 +8331,17 @@ class TestSymbolDatabase : public TestFixture {
83308331
ASSERT(Token::simpleMatch(f->function()->tokenDef, "f ( const Token * ptr ) ;"));
83318332
}
83328333

8334+
void findFunction56() { // #13125
8335+
GET_SYMBOL_DB("void f(const char* fn, int i, const char e[], const std::string& a);\n"
8336+
"void f(const char* fn, int i, const char e[], const char a[]);\n"
8337+
"void g(const char x[], const std::string& s) {\n"
8338+
" f(\"abc\", 65, x, s);\n"
8339+
"}\n");
8340+
const Token* f = Token::findsimplematch(tokenizer.tokens(), "f ( \"abc\"");
8341+
ASSERT(f && f->function());
8342+
ASSERT_EQUALS(f->function()->tokenDef->linenr(), 1);
8343+
}
8344+
83338345
void findFunctionRef1() {
83348346
GET_SYMBOL_DB("struct X {\n"
83358347
" const std::vector<int> getInts() const & { return mInts; }\n"

0 commit comments

Comments
 (0)