Fix endless recursion within CheckClass::isConstMemberFunc() caused by incomplete/missing template declaration

This commit is contained in:
Alexander Mai 2014-03-30 10:09:57 +02:00
parent bf335217cd
commit 70885c78e4
2 changed files with 20 additions and 1 deletions

View File

@ -1737,7 +1737,7 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
// find the function in the base class
if (derivedFrom && derivedFrom->classScope) {
if (derivedFrom && derivedFrom->classScope && !derivedFrom->hasCircularDependencies()) {
if (isConstMemberFunc(derivedFrom->classScope, tok))
return true;
}

View File

@ -4808,6 +4808,25 @@ private:
" }\n"
"};");
ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'MixerParticipant::InitializeFileReader' can be static.\n", errout.str());
// Based on an example from SVN source code causing an endless recursion within CheckClass::isConstMemberFunc()
// A more complete example including a template declaration like
// template<typename K> class Hash{/* ... */};
// didn't .
checkConst("template<>\n"
"class Hash<void> {\n"
"protected:\n"
" typedef Key::key_type key_type;\n"
" void set(const Key& key);\n"
"};\n"
"template<typename K, int KeySize>\n"
"class Hash : private Hash<void> {\n"
" typedef Hash<void> inherited;\n"
" void set(const Key& key) {\n"
" inherited::set(inherited::Key(key));\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}