CheckClass: made warnings about uninitialized members in default constructors inconclusive. Ticket: #4639
This commit is contained in:
parent
1fbef0e4e6
commit
25c36b56fa
|
@ -170,8 +170,18 @@ void CheckClass::constructors()
|
|||
operatorEqVarError(func->token, scope->className, var->name(), inconclusive);
|
||||
} else if (func->access != Private) {
|
||||
const Scope *varType = var->typeScope();
|
||||
if (!varType || varType->type != Scope::eUnion)
|
||||
uninitVarError(func->token, scope->className, var->name(), inconclusive);
|
||||
if (!varType || varType->type != Scope::eUnion) {
|
||||
if (func->type == Function::eConstructor &&
|
||||
func->nestedIn && (func->nestedIn->numConstructors - func->nestedIn->numCopyConstructors) > 1 &&
|
||||
func->argCount() == 0 && func->functionScope &&
|
||||
func->arg && func->arg->link()->next() == func->functionScope->classStart &&
|
||||
func->functionScope->classStart->link() == func->functionScope->classStart->next()) {
|
||||
// don't warn about user defined default constructor when there are other constructors
|
||||
if (_settings->inconclusive)
|
||||
uninitVarError(func->token, scope->className, var->name(), true);
|
||||
} else
|
||||
uninitVarError(func->token, scope->className, var->name(), inconclusive);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -421,9 +421,12 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
function.isConst = true;
|
||||
|
||||
// count the number of constructors
|
||||
if (function.type == Function::eConstructor ||
|
||||
function.type == Function::eCopyConstructor)
|
||||
if (function.type == Function::eConstructor)
|
||||
scope->numConstructors++;
|
||||
else if (function.type == Function::eCopyConstructor) {
|
||||
scope->numConstructors++;
|
||||
scope->numCopyConstructors++;
|
||||
}
|
||||
|
||||
// assume implementation is inline (definition and implementation same)
|
||||
function.token = function.tokenDef;
|
||||
|
@ -1943,6 +1946,7 @@ Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *
|
|||
classEnd(start_->link()),
|
||||
nestedIn(nestedIn_),
|
||||
numConstructors(0),
|
||||
numCopyConstructors(0),
|
||||
type(type_),
|
||||
definedType(NULL),
|
||||
functionOf(NULL),
|
||||
|
@ -1957,6 +1961,7 @@ Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *
|
|||
classEnd(NULL),
|
||||
nestedIn(nestedIn_),
|
||||
numConstructors(0),
|
||||
numCopyConstructors(0),
|
||||
definedType(NULL),
|
||||
functionOf(NULL),
|
||||
function(NULL)
|
||||
|
|
|
@ -519,6 +519,7 @@ public:
|
|||
const Scope *nestedIn;
|
||||
std::list<Scope *> nestedList;
|
||||
unsigned int numConstructors;
|
||||
unsigned int numCopyConstructors;
|
||||
std::list<UsingInfo> usingList;
|
||||
ScopeType type;
|
||||
Type* definedType;
|
||||
|
|
|
@ -261,8 +261,8 @@ private:
|
|||
"Fred::Fred(int _i)\n"
|
||||
"{\n"
|
||||
" i = _i;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str());
|
||||
"}\n", true);
|
||||
ASSERT_EQUALS("[test.cpp:7]: (warning, inconclusive) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str());
|
||||
}
|
||||
|
||||
void simple5() { // ticket #2560
|
||||
|
@ -835,9 +835,9 @@ private:
|
|||
"public:\n"
|
||||
" A(int n) : A() { }\n"
|
||||
" A() {}\n"
|
||||
"};");
|
||||
"};", true);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'A::number' is not initialized in the constructor.\n"
|
||||
"[test.cpp:5]: (warning) Member variable 'A::number' is not initialized in the constructor.\n", errout.str());
|
||||
"[test.cpp:5]: (warning, inconclusive) Member variable 'A::number' is not initialized in the constructor.\n", errout.str());
|
||||
|
||||
check("class A {\n"
|
||||
" int number;\n"
|
||||
|
@ -1781,9 +1781,9 @@ private:
|
|||
"::Foo::Sub::Sub() { }\n"
|
||||
"class Foo;\n"
|
||||
"class Bar;\n"
|
||||
"class Sub;\n");
|
||||
"class Sub;\n", true);
|
||||
|
||||
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Sub::b' is not initialized in the constructor.\n"
|
||||
ASSERT_EQUALS("[test.cpp:9]: (warning, inconclusive) Member variable 'Sub::b' is not initialized in the constructor.\n"
|
||||
"[test.cpp:12]: (warning) Member variable 'Sub::b' is not initialized in the constructor.\n"
|
||||
"[test.cpp:20]: (warning) Member variable 'Sub::f' is not initialized in the constructor.\n", errout.str());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue