From 5aab602709e8f46162075a2e300277728e337d62 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 31 Aug 2010 17:57:42 +0200 Subject: [PATCH] Fixed #2001 (No 'The function ... can be const' warnings when base class is in namespace.) --- lib/checkclass.cpp | 6 +++++- test/testclass.cpp | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index b8917e344..6c03f02bd 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -393,9 +393,13 @@ void CheckClass::createSymbolDatabase() /** @todo handle derived base classes and namespaces */ if (!spaceInfo->isNamespace) { + // do class names match? if (spaceInfo->className == info->derivedFrom[i].name) { - if (spaceInfo->nestedIn == info->nestedIn) + // are they in the same namespace or different namespaces with same name? + if ((spaceInfo->nestedIn == info->nestedIn) || + ((spaceInfo->nestedIn->isNamespace && info->nestedIn->isNamespace) && + (spaceInfo->nestedIn->className == info->nestedIn->className))) { info->derivedFrom[i].spaceInfo = spaceInfo; break; diff --git a/test/testclass.cpp b/test/testclass.cpp index 433cfc1d1..4db772e46 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -140,6 +140,7 @@ private: TEST_CASE(const32); // ticket #1905 - member array is assigned TEST_CASE(const33); TEST_CASE(const34); // ticket #1964 + TEST_CASE(const35); // ticket #2001 TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator2); // operator<< TEST_CASE(constoperator3); @@ -3931,6 +3932,26 @@ private: ASSERT_EQUALS("", errout.str()); } + void const35() // ticket #2001 + { + checkConst("namespace N\n" + "{\n" + " class Base\n" + " {\n" + " };\n" + "}\n" + "namespace N\n" + "{\n" + " class Derived : public Base\n" + " {\n" + " public:\n" + " int getResourceName() { return var; }\n" + " int var;\n" + " };\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:12]: (style) The function 'N::Derived::getResourceName' can be const\n", errout.str()); + } + // increment/decrement => not const void constincdec() {