Fix FP operatorEqVarError with class hierarchy (#3868)

This commit is contained in:
chrchr-github 2022-03-02 07:46:23 +01:00 committed by GitHub
parent 01de8256ea
commit 8e8e6b1170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -666,6 +666,8 @@ bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope)
if (func.tokenDef->str() == tok->str())
return true;
}
if (isBaseClassFunc(tok, derivedFrom->classScope))
return true;
}
// Base class not found so assume it is in it.

View File

@ -113,6 +113,7 @@ private:
TEST_CASE(initvar_operator_eq4); // ticket #2204
TEST_CASE(initvar_operator_eq5); // ticket #4119
TEST_CASE(initvar_operator_eq6);
TEST_CASE(initvar_operator_eq7);
TEST_CASE(initvar_same_classname); // BUG 2208157
TEST_CASE(initvar_chained_assign); // BUG 2270433
TEST_CASE(initvar_2constructors); // BUG 2270353
@ -910,6 +911,25 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Member variable 'Fred::data' is not assigned a value in 'Fred::operator='.\n", errout.str());
}
void initvar_operator_eq7() {
check("struct B {\n"
" virtual void CopyImpl(const B& Src) = 0;\n"
" void Copy(const B& Src);\n"
"};\n"
"struct D : B {};\n"
"struct DD : D {\n"
" void CopyImpl(const B& Src) override;\n"
" DD& operator=(const DD& Src);\n"
" int i{};\n"
"};\n"
"DD& DD::operator=(const DD& Src) {\n"
" if (this != &Src)\n"
" Copy(Src);\n"
" return *this;\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
}
void initvar_same_classname() {
// Bug 2208157 - False positive: Uninitialized variable, same class name