Merge pull request #192 from simartin/ticket_5125

Ticket #5125: Avoid infinite recursion for recursive class definitions
This commit is contained in:
Daniel Marjamäki 2013-10-29 21:19:34 -07:00
commit 7ccffe7761
2 changed files with 15 additions and 0 deletions

View File

@ -2510,6 +2510,8 @@ const Function* Scope::findFunction(const Token *tok) const
for (std::size_t i = 0; i < definedType->derivedFrom.size(); ++i) {
const Type *base = definedType->derivedFrom[i].type;
if (base && base->classScope) {
if (base->classScope == this) // Ticket #5125: Recursive class; tok should have been found already
continue;
const Function * func = base->classScope->findFunction(tok);
if (func)
return func;

View File

@ -199,6 +199,7 @@ private:
TEST_CASE(symboldatabase35); // ticket #4806 (segmentation fault)
TEST_CASE(symboldatabase36); // ticket #4892 (segmentation fault)
TEST_CASE(symboldatabase37);
TEST_CASE(symboldatabase38); // ticket #5125 (infinite recursion)
TEST_CASE(isImplicitlyVirtual);
@ -1639,6 +1640,18 @@ private:
ASSERT(db && db->getVariableFromVarId(3) && db->getVariableFromVarId(3)->type() && db->getVariableFromVarId(3)->type()->name() == "Barney");
}
void symboldatabase38() { // ticket #5125
check("template <typename T = class service> struct scoped_service;\n"
"struct service {};\n"
"template <> struct scoped_service<service> {};\n"
"template <typename T>\n"
"struct scoped_service : scoped_service<service>\n"
"{\n"
" scoped_service( T* ptr ) : scoped_service<service>(ptr), m_ptr(ptr) {}\n"
" T* const m_ptr;\n"
"};");
}
void isImplicitlyVirtual() {
{
GET_SYMBOL_DB("class Base {\n"