From 70885c78e448a38afd9528761271c7c33d629eb3 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sun, 30 Mar 2014 10:09:57 +0200 Subject: [PATCH] Fix endless recursion within CheckClass::isConstMemberFunc() caused by incomplete/missing template declaration --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 8480731de..3d124a812 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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; } diff --git a/test/testclass.cpp b/test/testclass.cpp index c7bd7c419..ef8287224 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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 class Hash{/* ... */}; + // didn't . + checkConst("template<>\n" + "class Hash {\n" + "protected:\n" + " typedef Key::key_type key_type;\n" + " void set(const Key& key);\n" + "};\n" + "template\n" + "class Hash : private Hash {\n" + " typedef Hash inherited;\n" + " void set(const Key& key) {\n" + " inherited::set(inherited::Key(key));\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); }