MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / isInitialized

Method isInitialized

lib/checkclass.cpp:114–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112{}
113
114bool CheckClassImpl::isInitialized(const Usage& usage, FunctionType funcType) const
115{
116 const Variable& var = *usage.var;
117
118 if (usage.assign || usage.init || var.isStatic())
119 return true;
120
121 if (!var.nameToken() || var.nameToken()->isAnonymous())
122 return true;
123
124 if (var.valueType() && var.valueType()->pointer == 0 && var.type() && var.type()->needInitialization == Type::NeedInitialization::False && var.type()->derivedFrom.empty())
125 return true;
126
127 if (var.isConst() && funcType == FunctionType::eOperatorEqual) // We can't set const members in assignment operator
128 return true;
129
130 // Check if this is a class constructor
131 if (!var.isPointer() && !var.isPointerArray() && var.isClass() && funcType == FunctionType::eConstructor) {
132 // Unknown type so assume it is initialized
133 if (!var.type()) {
134 if (var.isStlType() && var.valueType() && var.valueType()->containerTypeToken) {
135 if (var.valueType()->type == ValueType::Type::ITERATOR)
136 {
137 // needs initialization
138 }
139 else if (var.getTypeName() == "std::array") {
140 const Token* ctt = var.valueType()->containerTypeToken;
141 if (!ctt->isStandardType() &&
142 (!ctt->type() || ctt->type()->needInitialization != Type::NeedInitialization::True) &&
143 !mSettings.library.podtype(ctt->str())) // TODO: handle complex type expression
144 return true;
145 }
146 else
147 return true;
148 }
149 else
150 return true;
151 }
152
153 // Known type that doesn't need initialization or
154 // known type that has member variables of an unknown type
155 else if (var.type()->needInitialization != Type::NeedInitialization::True)
156 return true;
157 }
158
159 // Check if type can't be copied
160 if (!var.isPointer() && !var.isPointerArray() && var.typeScope()) {
161 if (funcType == FunctionType::eMoveConstructor) {
162 if (canNotMove(var.typeScope()))
163 return true;
164 }
165 else {
166 if (canNotCopy(var.typeScope()))
167 return true;
168 }
169 }
170 return false;
171}

Callers

nothing calls this directly

Calls 10

typeMethod · 0.80
isConstMethod · 0.80
isPointerArrayMethod · 0.80
isClassMethod · 0.80
getTypeNameMethod · 0.80
nameTokenMethod · 0.45
emptyMethod · 0.45
isStandardTypeMethod · 0.45
podtypeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected