Fixed #7790 (Wrong order of <location> XML-elements for error duplInheritedMember)
This commit is contained in:
parent
19af19b15e
commit
4d78a2e178
|
@ -2435,17 +2435,19 @@ void CheckClass::checkDuplInheritedMembers()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::duplInheritedMembersError(const Token *tok1, const Token* tok2,
|
void CheckClass::duplInheritedMembersError(const Token *tok1, const Token* tok2,
|
||||||
const std::string &derivedname, const std::string &basename,
|
const std::string &derivedName, const std::string &baseName,
|
||||||
const std::string &variablename, bool derivedIsStruct, bool baseIsStruct)
|
const std::string &variableName, bool derivedIsStruct, bool baseIsStruct)
|
||||||
{
|
{
|
||||||
std::list<const Token *> toks = { tok1, tok2 };
|
ErrorPath errorPath;
|
||||||
|
errorPath.emplace_back(tok2, "Parent variable '" + baseName + "::" + variableName + "'");
|
||||||
|
errorPath.emplace_back(tok1, "Derived variable '" + derivedName + "::" + variableName + "'");
|
||||||
|
|
||||||
const std::string symbols = "$symbol:" + derivedname + "\n$symbol:" + variablename + "\n$symbol:" + basename;
|
const std::string symbols = "$symbol:" + derivedName + "\n$symbol:" + variableName + "\n$symbol:" + baseName;
|
||||||
|
|
||||||
const std::string message = "The " + std::string(derivedIsStruct ? "struct" : "class") + " '" + derivedname +
|
const std::string message = "The " + std::string(derivedIsStruct ? "struct" : "class") + " '" + derivedName +
|
||||||
"' defines member variable with name '" + variablename + "' also defined in its parent " +
|
"' defines member variable with name '" + variableName + "' also defined in its parent " +
|
||||||
std::string(baseIsStruct ? "struct" : "class") + " '" + basename + "'.";
|
std::string(baseIsStruct ? "struct" : "class") + " '" + baseName + "'.";
|
||||||
reportError(toks, Severity::warning, "duplInheritedMember", symbols + '\n' + message, CWE398, false);
|
reportError(errorPath, Severity::warning, "duplInheritedMember", symbols + '\n' + message, CWE398, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ private:
|
||||||
void selfInitializationError(const Token* tok, const std::string& varname);
|
void selfInitializationError(const Token* tok, const std::string& varname);
|
||||||
void pureVirtualFunctionCallInConstructorError(const Function * scopeFunction, const std::list<const Token *> & tokStack, const std::string &purefuncname);
|
void pureVirtualFunctionCallInConstructorError(const Function * scopeFunction, const std::list<const Token *> & tokStack, const std::string &purefuncname);
|
||||||
void virtualFunctionCallInConstructorError(const Function * scopeFunction, const std::list<const Token *> & tokStack, const std::string &funcname);
|
void virtualFunctionCallInConstructorError(const Function * scopeFunction, const std::list<const Token *> & tokStack, const std::string &funcname);
|
||||||
void duplInheritedMembersError(const Token* tok1, const Token* tok2, const std::string &derivedname, const std::string &basename, const std::string &variablename, bool derivedIsStruct, bool baseIsStruct);
|
void duplInheritedMembersError(const Token* tok1, const Token* tok2, const std::string &derivedName, const std::string &baseName, const std::string &variableName, bool derivedIsStruct, bool baseIsStruct);
|
||||||
void copyCtorAndEqOperatorError(const Token *tok, const std::string &classname, bool isStruct, bool hasCopyCtor);
|
void copyCtorAndEqOperatorError(const Token *tok, const std::string &classname, bool isStruct, bool hasCopyCtor);
|
||||||
void unsafeClassDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName);
|
void unsafeClassDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName);
|
||||||
void overrideError(const Function *funcInBase, const Function *funcInDerived);
|
void overrideError(const Function *funcInBase, const Function *funcInDerived);
|
||||||
|
|
|
@ -457,7 +457,7 @@ private:
|
||||||
"struct Derived : Base {\n"
|
"struct Derived : Base {\n"
|
||||||
" int x;\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());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base'.\n", errout.str());
|
||||||
|
|
||||||
checkDuplInheritedMembers("class Base {\n"
|
checkDuplInheritedMembers("class Base {\n"
|
||||||
" protected:\n"
|
" protected:\n"
|
||||||
|
@ -466,7 +466,7 @@ private:
|
||||||
"struct Derived : public Base {\n"
|
"struct Derived : public Base {\n"
|
||||||
" int x;\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());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (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"
|
||||||
|
@ -489,7 +489,7 @@ private:
|
||||||
"struct Derived : Base0, Base1 {\n"
|
"struct Derived : Base0, Base1 {\n"
|
||||||
" int x;\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());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:9]: (warning) The struct 'Derived' defines member variable with name 'x' also defined in its parent class 'Base0'.\n", errout.str());
|
||||||
|
|
||||||
checkDuplInheritedMembers("class Base0 {\n"
|
checkDuplInheritedMembers("class Base0 {\n"
|
||||||
" protected:\n"
|
" protected:\n"
|
||||||
|
@ -502,8 +502,8 @@ private:
|
||||||
"struct Derived : Base0, Base1 {\n"
|
"struct Derived : Base0, Base1 {\n"
|
||||||
" int x;\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"
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:10]: (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());
|
"[test.cpp:7] -> [test.cpp:10]: (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