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

Method reportErr

lib/cppcheck.cpp:160–249  ·  view source on GitHub ↗

* @brief Errors and warnings are directed here. * * @param msg Errors messages are normally in format * "[filepath:line number] Message", e.g. * "[main.cpp:4] Uninitialized member variable" */ TODO: part of this logic is duplicated in Executor::hasToLog()

Source from the content-addressed store, hash-verified

158 */
159 // TODO: part of this logic is duplicated in Executor::hasToLog()
160 void reportErr(const ErrorMessage &msg) override
161 {
162 if (msg.severity == Severity::internal) {
163 mErrorLogger.reportErr(msg);
164 return;
165 }
166
167 if (!mSettings.library.reportErrors(msg.file0))
168 return;
169
170 std::set<std::string> macroNames;
171 if (!msg.callStack.empty()) {
172 const std::string &file = msg.callStack.back().getfile(false);
173 int lineNumber = msg.callStack.back().line;
174 const auto it = mLocationMacros.find(Location(file, lineNumber));
175 if (it != mLocationMacros.cend())
176 macroNames = it->second;
177 }
178
179 // TODO: only convert if necessary
180 const auto errorMessage = SuppressionList::ErrorMessage::fromErrorMessage(msg, macroNames);
181
182 bool suppressed = false;
183
184 if (mSuppressions.nomsg.isSuppressed(errorMessage, mUseGlobalSuppressions)) {
185 // Safety: Report critical errors to ErrorLogger
186 if (mSettings.safety && ErrorLogger::isCriticalErrorId(msg.id)) {
187 mExitCode = 1;
188
189 if (mSuppressions.nomsg.isSuppressedExplicitly(errorMessage, mUseGlobalSuppressions)) {
190 // Report with internal severity to signal that there is this critical error but
191 // it is suppressed
192 ErrorMessage temp(msg);
193 temp.severity = Severity::internal;
194 mErrorLogger.reportErr(temp);
195 } else {
196 // Report critical error that is not explicitly suppressed
197 mErrorLogger.reportErr(msg);
198 }
199 }
200 suppressed = true;
201 }
202
203 // TODO: there should be no need for the verbose and default messages here
204 std::string errmsg = msg.toString(mSettings.verbose, mSettings.templateFormat, mSettings.templateLocation);
205 if (errmsg.empty())
206 return;
207
208 // Alert only about unique errors.
209 // This makes sure the errors of a single check() call are unique.
210 // TODO: get rid of this? This is forwarded to another ErrorLogger which is also doing this
211 if (!mSettings.emitDuplicates && !mErrorList.emplace(std::move(errmsg)).second)
212 return;
213
214 if (mAnalyzerInformation)
215 mAnalyzerInformation->reportErr(msg);
216
217 if (suppressed)

Callers 10

checkClangMethod · 0.45
checkInternalMethod · 0.45
internalErrorMethod · 0.45
checkNormalTokensMethod · 0.45
executeRulesMethod · 0.45
executeAddonsMethod · 0.45
tooManyConfigsErrorMethod · 0.45
analyseClangTidyMethod · 0.45
analyseWholeProgramMethod · 0.45

Calls 9

isCriticalErrorIdFunction · 0.85
reportErrorsMethod · 0.80
getfileMethod · 0.80
LocationClass · 0.70
emptyMethod · 0.45
findMethod · 0.45
isSuppressedMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected