Skip to content

Commit 70885c7

Browse files
committed
Fix endless recursion within CheckClass::isConstMemberFunc() caused by incomplete/missing template declaration
1 parent bf33521 commit 70885c7

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
17371737
const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
17381738

17391739
// find the function in the base class
1740-
if (derivedFrom && derivedFrom->classScope) {
1740+
if (derivedFrom && derivedFrom->classScope && !derivedFrom->hasCircularDependencies()) {
17411741
if (isConstMemberFunc(derivedFrom->classScope, tok))
17421742
return true;
17431743
}

test/testclass.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4808,6 +4808,25 @@ class TestClass : public TestFixture {
48084808
" }\n"
48094809
"};");
48104810
ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'MixerParticipant::InitializeFileReader' can be static.\n", errout.str());
4811+
4812+
// Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()
4813+
// A more complete example including a template declaration like
4814+
// template<typename K> class Hash{/* ... */};
4815+
// didn't .
4816+
checkConst("template<>\n"
4817+
"class Hash<void> {\n"
4818+
"protected:\n"
4819+
" typedef Key::key_type key_type;\n"
4820+
" void set(const Key& key);\n"
4821+
"};\n"
4822+
"template<typename K, int KeySize>\n"
4823+
"class Hash : private Hash<void> {\n"
4824+
" typedef Hash<void> inherited;\n"
4825+
" void set(const Key& key) {\n"
4826+
" inherited::set(inherited::Key(key));\n"
4827+
" }\n"
4828+
"};\n");
4829+
ASSERT_EQUALS("", errout.str());
48114830
}
48124831

48134832

0 commit comments

Comments
 (0)