Fix FP operatorEqVarError with class hierarchy (#3868)
This commit is contained in:
parent
01de8256ea
commit
8e8e6b1170
|
@ -666,6 +666,8 @@ bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope)
|
||||||
if (func.tokenDef->str() == tok->str())
|
if (func.tokenDef->str() == tok->str())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (isBaseClassFunc(tok, derivedFrom->classScope))
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Base class not found so assume it is in it.
|
// Base class not found so assume it is in it.
|
||||||
|
|
|
@ -113,6 +113,7 @@ private:
|
||||||
TEST_CASE(initvar_operator_eq4); // ticket #2204
|
TEST_CASE(initvar_operator_eq4); // ticket #2204
|
||||||
TEST_CASE(initvar_operator_eq5); // ticket #4119
|
TEST_CASE(initvar_operator_eq5); // ticket #4119
|
||||||
TEST_CASE(initvar_operator_eq6);
|
TEST_CASE(initvar_operator_eq6);
|
||||||
|
TEST_CASE(initvar_operator_eq7);
|
||||||
TEST_CASE(initvar_same_classname); // BUG 2208157
|
TEST_CASE(initvar_same_classname); // BUG 2208157
|
||||||
TEST_CASE(initvar_chained_assign); // BUG 2270433
|
TEST_CASE(initvar_chained_assign); // BUG 2270433
|
||||||
TEST_CASE(initvar_2constructors); // BUG 2270353
|
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());
|
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() {
|
void initvar_same_classname() {
|
||||||
// Bug 2208157 - False positive: Uninitialized variable, same class name
|
// Bug 2208157 - False positive: Uninitialized variable, same class name
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue