Fixed #3611 (CheckClass: uninitVar and operatorEqVarError false positives (non-copyable members))
This commit is contained in:
parent
eb5a61edfe
commit
7d3e661774
|
@ -129,6 +129,17 @@ void CheckClass::constructors()
|
||||||
if (!var->isPointer() && var->type() && canNotCopy(var->type()))
|
if (!var->isPointer() && var->type() && canNotCopy(var->type()))
|
||||||
continue;
|
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
|
// It's non-static and it's not initialized => error
|
||||||
if (func->type == Function::eOperatorEqual) {
|
if (func->type == Function::eOperatorEqual) {
|
||||||
const Token *operStart = func->arg;
|
const Token *operStart = func->arg;
|
||||||
|
|
|
@ -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());
|
"[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() {
|
void initvar_destructor() {
|
||||||
check("class Fred\n"
|
check("class Fred\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue