Fixed #3611 (CheckClass: uninitVar and operatorEqVarError false positives (non-copyable members))

This commit is contained in:
Daniel Marjamäki 2012-09-20 16:47:01 +02:00
parent eb5a61edfe
commit 7d3e661774
2 changed files with 20 additions and 0 deletions

View File

@ -129,6 +129,17 @@ void CheckClass::constructors()
if (!var->isPointer() && var->type() && canNotCopy(var->type()))
continue;
// Don't warn about unknown types in copy constructors since we
// don't know if they can be copied or not..
if (!var->isPointer() && !var->isClass() && (func->type == Function::eCopyConstructor || func->type == Function::eOperatorEqual)) {
bool stdtype = false;
for (const Token *type = var->typeStartToken(); type && type->isName(); type = type->next()) {
stdtype |= type->isStandardType();
}
if (!stdtype)
continue;
}
// It's non-static and it's not initialized => error
if (func->type == Function::eOperatorEqual) {
const Token *operStart = func->arg;

View File

@ -861,6 +861,15 @@ private:
"[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='.\n", errout.str());
}
void initvar_nocopy3() { // #3611 - unknown type is non-copyable
check("struct A {\n"
" B b;\n"
" A() {}\n"
" A(const A& rhs) {}\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void initvar_destructor() {
check("class Fred\n"
"{\n"