Fix 9215 (add tilde for missing destructor override warning) (#2057)
This commit is contained in:
parent
4704b1d331
commit
f6726b76ae
|
@ -2648,17 +2648,18 @@ void CheckClass::checkOverride()
|
||||||
|
|
||||||
void CheckClass::overrideError(const Function *funcInBase, const Function *funcInDerived)
|
void CheckClass::overrideError(const Function *funcInBase, const Function *funcInDerived)
|
||||||
{
|
{
|
||||||
const std::string functionName = funcInDerived ? funcInDerived->name() : "";
|
const std::string functionName = funcInDerived ? ((funcInDerived->isDestructor() ? "~" : "") + funcInDerived->name()) : "";
|
||||||
|
const std::string funcType = (funcInDerived && funcInDerived->isDestructor()) ? "destructor" : "function";
|
||||||
|
|
||||||
ErrorPath errorPath;
|
ErrorPath errorPath;
|
||||||
if (funcInBase && funcInDerived) {
|
if (funcInBase && funcInDerived) {
|
||||||
errorPath.push_back(ErrorPathItem(funcInBase->tokenDef, "Virtual function in base class"));
|
errorPath.push_back(ErrorPathItem(funcInBase->tokenDef, "Virtual " + funcType + " in base class"));
|
||||||
errorPath.push_back(ErrorPathItem(funcInDerived->tokenDef, "Function in derived class"));
|
errorPath.push_back(ErrorPathItem(funcInDerived->tokenDef, char(std::toupper(funcType[0])) + funcType.substr(1) + " in derived class"));
|
||||||
}
|
}
|
||||||
|
|
||||||
reportError(errorPath, Severity::style, "missingOverride",
|
reportError(errorPath, Severity::style, "missingOverride",
|
||||||
"$symbol:" + functionName + "\n"
|
"$symbol:" + functionName + "\n"
|
||||||
"The function '$symbol' overrides a function in a base class but is not marked with a 'override' specifier.",
|
"The " + funcType + " '$symbol' overrides a " + funcType + " in a base class but is not marked with a 'override' specifier.",
|
||||||
CWE(0U) /* Unknown CWE! */,
|
CWE(0U) /* Unknown CWE! */,
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7128,6 +7128,19 @@ private:
|
||||||
" auto bar( ) const -> size_t override { return 0; }\n"
|
" auto bar( ) const -> size_t override { return 0; }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:8]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:8]: (style) The function 'foo' overrides a function in a base class but is not marked with a 'override' specifier.\n", errout.str());
|
||||||
|
|
||||||
|
checkOverride("namespace Test {\n"
|
||||||
|
" class C {\n"
|
||||||
|
" public:\n"
|
||||||
|
" virtual ~C();\n"
|
||||||
|
" };\n"
|
||||||
|
"}\n"
|
||||||
|
"class C : Test::C {\n"
|
||||||
|
"public:\n"
|
||||||
|
" ~C();\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:9]: (style) The destructor '~C' overrides a destructor in a base class but is not marked with a 'override' specifier.\n", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void overrideCVRefQualifiers() {
|
void overrideCVRefQualifiers() {
|
||||||
|
|
Loading…
Reference in New Issue