SymbolDatabase: improved handling of const in function parameters

This commit is contained in:
Robert Reif 2013-01-27 02:46:00 +01:00 committed by Daniel Marjamäki
parent 6dc9987ad0
commit a0d8fd26fe
2 changed files with 19 additions and 0 deletions

View File

@ -1049,6 +1049,12 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
second = second->next();
}
// skip const on type passed by value
if (Token::Match(first, "const %type% %var%|,|)"))
first = first->next();
if (Token::Match(second, "const %type% %var%|,|)"))
second = second->next();
while (first->str() == second->str()) {
// at end of argument list
if (first->str() == ")") {
@ -1138,6 +1144,12 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
if (second->str() == "struct")
second = second->next();
}
// skip const on type passed by value
if (Token::Match(first, "const %type% %var%|,|)"))
first = first->next();
if (Token::Match(second, "const %type% %var%|,|)"))
second = second->next();
}
return false;

View File

@ -156,6 +156,7 @@ private:
TEST_CASE(symboldatabase27); // ticket #3543 (segmentation fault)
TEST_CASE(symboldatabase28);
TEST_CASE(symboldatabase29); // ticket #4442 (segmentation fault)
TEST_CASE(symboldatabase30);
TEST_CASE(isImplicitlyVirtual);
@ -1351,6 +1352,12 @@ private:
ASSERT_EQUALS("", errout.str());
}
void symboldatabase30() {
GET_SYMBOL_DB("struct A { void foo(const int a); };\n"
"void A::foo(int a) { }");
ASSERT(db && db->functionScopes.size() == 1 && db->functionScopes[0]->functionOf);
}
void isImplicitlyVirtual() {
{
GET_SYMBOL_DB("class Base {\n"