Fixed #5122 (duplInheritedMember on private variables)
This commit is contained in:
parent
ef108c49ec
commit
7d45e9be73
|
@ -1973,7 +1973,7 @@ void CheckClass::checkDuplInheritedMembers()
|
||||||
for (std::list<Variable>::const_iterator parentClassVarIt = parentClassIt->type->classScope->varlist.begin();
|
for (std::list<Variable>::const_iterator parentClassVarIt = parentClassIt->type->classScope->varlist.begin();
|
||||||
parentClassVarIt != parentClassIt->type->classScope->varlist.end();
|
parentClassVarIt != parentClassIt->type->classScope->varlist.end();
|
||||||
++parentClassVarIt) {
|
++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(),
|
duplInheritedMembersError(classVarIt->nameToken(), parentClassVarIt->nameToken(),
|
||||||
classIt->name(), parentClassIt->type->name(), classVarIt->name(),
|
classIt->name(), parentClassIt->type->name(), classVarIt->name(),
|
||||||
classIt->classScope->type == Scope::eStruct,
|
classIt->classScope->type == Scope::eStruct,
|
||||||
|
|
|
@ -205,7 +205,25 @@ private:
|
||||||
"struct Derived : Base {\n"
|
"struct Derived : Base {\n"
|
||||||
" int x;\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"
|
checkDuplInheritedMembers("class Base0 {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
|
@ -216,8 +234,33 @@ private:
|
||||||
"struct Derived : Base0, Base1 {\n"
|
"struct Derived : Base0, Base1 {\n"
|
||||||
" int x;\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"
|
ASSERT_EQUALS("", errout.str());
|
||||||
"[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());
|
|
||||||
|
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"
|
checkDuplInheritedMembers("class Base {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
|
|
Loading…
Reference in New Issue