From a0d8fd26fe822d39fb591e304386fe8481a7ca1a Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sun, 27 Jan 2013 02:46:00 +0100 Subject: [PATCH] SymbolDatabase: improved handling of const in function parameters --- lib/symboldatabase.cpp | 12 ++++++++++++ test/testsymboldatabase.cpp | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c34c8ddc6..f6ae11925 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index e2386a39f..82b90ef01 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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"