Fixed #5122 (duplInheritedMember on private variables)

This commit is contained in:
Alexander Mai 2013-11-21 05:39:23 +01:00 committed by Daniel Marjamäki
parent ef108c49ec
commit 7d45e9be73
2 changed files with 47 additions and 4 deletions

View File

@ -1973,7 +1973,7 @@ void CheckClass::checkDuplInheritedMembers()
for (std::list<Variable>::const_iterator parentClassVarIt = parentClassIt->type->classScope->varlist.begin();
parentClassVarIt != parentClassIt->type->classScope->varlist.end();
++parentClassVarIt) {
if (classVarIt->name() == parentClassVarIt->name()) { // Check if the class and its parent have a common variable
if (classVarIt->name() == parentClassVarIt->name() && !parentClassVarIt->isPrivate()) { // Check if the class and its parent have a common variable
duplInheritedMembersError(classVarIt->nameToken(), parentClassVarIt->nameToken(),
classIt->name(), parentClassIt->type->name(), classVarIt->name(),
classIt->classScope->type == Scope::eStruct,

View File

@ -205,7 +205,25 @@ private:
"struct Derived : Base {\n"
" int x;\n"
"};");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:2]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout.str());
ASSERT_EQUALS("", errout.str());
checkDuplInheritedMembers("class Base {\n"
" protected:\n"
" int x;\n"
"};\n"
"struct Derived : Base {\n"
" int x;\n"
"};");
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:3]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout.str());
checkDuplInheritedMembers("class Base {\n"
" protected:\n"
" int x;\n"
"};\n"
"struct Derived : public Base {\n"
" int x;\n"
"};");
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:3]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout.str());
checkDuplInheritedMembers("class Base0 {\n"
" int x;\n"
@ -216,8 +234,33 @@ private:
"struct Derived : Base0, Base1 {\n"
" int x;\n"
"};");
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:2]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'.\n"
"[test.cpp:8] -> [test.cpp:5]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'.\n", errout.str());
ASSERT_EQUALS("", errout.str());
checkDuplInheritedMembers("class Base0 {\n"
" protected:\n"
" int x;\n"
"};\n"
"class Base1 {\n"
" int x;\n"
"};\n"
"struct Derived : Base0, Base1 {\n"
" int x;\n"
"};");
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'.\n", errout.str());
checkDuplInheritedMembers("class Base0 {\n"
" protected:\n"
" int x;\n"
"};\n"
"class Base1 {\n"
" public:\n"
" int x;\n"
"};\n"
"struct Derived : Base0, Base1 {\n"
" int x;\n"
"};");
ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:3]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'.\n"
"[test.cpp:10] -> [test.cpp:7]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base1'.\n", errout.str());
checkDuplInheritedMembers("class Base {\n"
" int x;\n"