Skip to content

Commit 052be76

Browse files
committed
Ticket danmar#5125: Avoid infinite recursion for recursive class definitions
1 parent 097510c commit 052be76

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/symboldatabase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,8 @@ const Function* Scope::findFunction(const Token *tok) const
25102510
for (std::size_t i = 0; i < definedType->derivedFrom.size(); ++i) {
25112511
const Type *base = definedType->derivedFrom[i].type;
25122512
if (base && base->classScope) {
2513+
if (base->classScope == this) // Ticket #5125: Recursive class; tok should have been found already
2514+
continue;
25132515
const Function * func = base->classScope->findFunction(tok);
25142516
if (func)
25152517
return func;

test/testsymboldatabase.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class TestSymbolDatabase: public TestFixture {
199199
TEST_CASE(symboldatabase35); // ticket #4806 (segmentation fault)
200200
TEST_CASE(symboldatabase36); // ticket #4892 (segmentation fault)
201201
TEST_CASE(symboldatabase37);
202+
TEST_CASE(symboldatabase38); // ticket #5125 (infinite recursion)
202203

203204
TEST_CASE(isImplicitlyVirtual);
204205

@@ -1639,6 +1640,18 @@ class TestSymbolDatabase: public TestFixture {
16391640
ASSERT(db && db->getVariableFromVarId(3) && db->getVariableFromVarId(3)->type() && db->getVariableFromVarId(3)->type()->name() == "Barney");
16401641
}
16411642

1643+
void symboldatabase38() { // ticket #5125
1644+
check("template <typename T = class service> struct scoped_service;\n"
1645+
"struct service {};\n"
1646+
"template <> struct scoped_service<service> {};\n"
1647+
"template <typename T>\n"
1648+
"struct scoped_service : scoped_service<service>\n"
1649+
"{\n"
1650+
" scoped_service( T* ptr ) : scoped_service<service>(ptr), m_ptr(ptr) {}\n"
1651+
" T* const m_ptr;\n"
1652+
"};");
1653+
}
1654+
16421655
void isImplicitlyVirtual() {
16431656
{
16441657
GET_SYMBOL_DB("class Base {\n"

0 commit comments

Comments
 (0)