Fixed #2001 (No 'The function ... can be const' warnings when base class is in namespace.)

This commit is contained in:
Robert Reif 2010-08-31 17:57:42 +02:00 committed by Daniel Marjamäki
parent c56911ba6a
commit 5aab602709
2 changed files with 26 additions and 1 deletions

View File

@ -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;

View File

@ -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()
{