Fixed #8558 (False portability positive caused by incorrect method resolution)

This commit is contained in:
Daniel Marjamäki 2019-05-30 19:24:27 +02:00
parent a27c88f99b
commit 36b6fb9f4d
2 changed files with 21 additions and 1 deletions

View File

@ -4310,7 +4310,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
// check if all arguments matched
if (same == hasToBe) {
if (constFallback)
if (constFallback || (!requireConst && func->isConst()))
fallback1Func = func;
else
return func;

View File

@ -336,6 +336,7 @@ private:
TEST_CASE(findFunction18);
TEST_CASE(findFunction19);
TEST_CASE(findFunction20); // #8280
TEST_CASE(findFunction21);
TEST_CASE(noexceptFunction1);
TEST_CASE(noexceptFunction2);
@ -5408,6 +5409,25 @@ private:
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 12);
}
void findFunction21() { // # 8558
GET_SYMBOL_DB("struct foo {\n"
" int GetThing( ) const { return m_thing; }\n"
" int* GetThing( ) { return &m_thing; }\n"
"};\n"
"\n"
"void f(foo *myFoo) {\n"
" int* myThing = myFoo->GetThing();\n"
"}");
ASSERT(db != nullptr);
const Token *tok1 = Token::findsimplematch(tokenizer.tokens(), "myFoo . GetThing ( ) ;");
const Function *f = tok1 && tok1->tokAt(2) ? tok1->tokAt(2)->function() : nullptr;
ASSERT(f != nullptr);
ASSERT_EQUALS(true, f && f->tokenDef->linenr() == 3);
}
#define FUNC(x) const Function *x = findFunctionByName(#x, &db->scopeList.front()); \
ASSERT_EQUALS(true, x != nullptr); \
if (x) ASSERT_EQUALS(true, x->isNoExcept());