Merge pull request #931 from IOBYTE/master
Fixed #8142 (false positive: The class 'B' has 'copy constructor' but lack of 'operator='
This commit is contained in:
commit
39955973e9
|
@ -2383,7 +2383,13 @@ void CheckClass::checkCopyCtorAndEqOperator()
|
||||||
for (std::size_t i = 0; i < classes; ++i) {
|
for (std::size_t i = 0; i < classes; ++i) {
|
||||||
const Scope * scope = symbolDatabase->classAndStructScopes[i];
|
const Scope * scope = symbolDatabase->classAndStructScopes[i];
|
||||||
|
|
||||||
if (scope->varlist.empty())
|
// count the number of non-static variables
|
||||||
|
int vars = 0;
|
||||||
|
for (std::list<Variable>::const_iterator var = scope->varlist.begin(); var != scope->varlist.end(); ++var) {
|
||||||
|
if (!var->isStatic())
|
||||||
|
vars++;
|
||||||
|
}
|
||||||
|
if (vars == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int hasCopyCtor = 0;
|
int hasCopyCtor = 0;
|
||||||
|
|
|
@ -254,6 +254,26 @@ private:
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkCopyCtorAndEqOperator("class A {\n"
|
||||||
|
"public:\n"
|
||||||
|
" A() : x(0) { }\n"
|
||||||
|
" A(const A & a) { x = a.x; }\n"
|
||||||
|
" A & operator = (const A & a) {\n"
|
||||||
|
" x = a.x;\n"
|
||||||
|
" return *this;\n"
|
||||||
|
" }\n"
|
||||||
|
"private:\n"
|
||||||
|
" int x;\n"
|
||||||
|
"};\n"
|
||||||
|
"class B : public A {\n"
|
||||||
|
"public:\n"
|
||||||
|
" B() { }\n"
|
||||||
|
" B(const B & b) :A(b) { }\n"
|
||||||
|
"private:\n"
|
||||||
|
" static int i;\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkExplicitConstructors(const char code[]) {
|
void checkExplicitConstructors(const char code[]) {
|
||||||
|
|
Loading…
Reference in New Issue