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

Method check

lib/checkunusedfunctions.cpp:369–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367 } while (false)
368
369bool CheckUnusedFunctions::check(const Settings& settings, ErrorLogger& errorLogger) const
370{
371 logChecker("CheckUnusedFunctions::check"); // unusedFunction
372
373 // filename, fileindex, line, column
374 using ErrorParams = std::tuple<std::string, nonneg int, nonneg int, nonneg int, std::string>;
375 std::vector<ErrorParams> errors; // ensure well-defined order
376 std::vector<ErrorParams> staticFunctionErrors;
377
378 for (auto it = mFunctions.cbegin(); it != mFunctions.cend(); ++it) {
379 const FunctionUsage &func = it->second;
380 if (func.usedOtherFile || func.filename.empty())
381 continue;
382 if (settings.library.isentrypoint(it->first))
383 continue;
384 if (!func.usedSameFile) {
385 if (isOperatorFunction(it->first))
386 continue;
387 std::string filename;
388 if (func.filename != "+")
389 filename = func.filename;
390 errors.emplace_back(filename, func.fileIndex, func.lineNumber, func.column, it->first);
391 } else if (func.isC && !func.isStatic) {
392 std::string filename;
393 if (func.filename != "+")
394 filename = func.filename;
395 staticFunctionErrors.emplace_back(filename, func.fileIndex, func.lineNumber, func.column, it->first);
396 }
397 }
398
399 std::sort(errors.begin(), errors.end());
400 for (const auto& e : errors)
401 unusedFunctionError(errorLogger, std::get<0>(e), std::get<1>(e), std::get<2>(e), std::get<3>(e), std::get<4>(e));
402
403 std::sort(staticFunctionErrors.begin(), staticFunctionErrors.end());
404 for (const auto& e : staticFunctionErrors)
405 staticFunctionError(errorLogger, std::get<0>(e), std::get<1>(e), std::get<2>(e), std::get<3>(e), std::get<4>(e));
406
407 return !errors.empty();
408}
409
410void CheckUnusedFunctions::unusedFunctionError(ErrorLogger& errorLogger,
411 const std::string &filename, nonneg int fileIndex, nonneg int lineNumber, nonneg int column,

Callers

nothing calls this directly

Calls 5

isOperatorFunctionFunction · 0.85
isentrypointMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected