Skip to content

fix(cxx): cppcheck include-path harvesting and information-record classification - #723

Open
karabelaselias wants to merge 1 commit into
peteromallet:mainfrom
karabelaselias:fix/cppcheck-include-path-and-information-filter
Open

karabelaselias wants to merge 1 commit into
peteromallet:mainfrom
karabelaselias:fix/cppcheck-include-path-and-information-filter

Conversation

@karabelaselias

Copy link
Copy Markdown

Problem

On C++ projects whose sources include headers outside the scanned tree (vendored or sibling-package code), the cppcheck phase produced unactionable findings:

  1. _cppcheck_include_args derived -I dirs only from in-scope headers, so external include roots recorded in the project's own compile_commands.json were never passed to cppcheck — every external header emitted missingInclude records.
  2. cppcheck's information category (missing include paths, checker reports, normalization notes) is non-actionable by definition but was captured as findings.

Fix

  • Harvest -I paths from compile_commands.json entries matching the scanned files, falling back gracefully when the database is absent or malformed.
  • Classify information-severity records as non-actionable in the phase filter.

Verification

  • New unit tests: information-record classifier, compile-db harvesting, malformed-database handling.
  • Full upstream suite: 5818 passed, 3 skipped.
  • Real-world check: C++17 rod-solver repo (114 files) — 47 information-level records and recurring missingInclude noise dissolved after the fix.

…fy cppcheck information records

Two root causes produced unactionable cppcheck findings on C++ projects
whose sources include headers outside the scanned tree (vendored or
sibling-package code):

1. _cppcheck_include_args derived -I dirs only from in-scope headers, so
   external include roots (recorded in the project's own
   compile_commands.json) were never passed to cppcheck and every
   external header produced missingInclude records. Harvest -I paths
   from compile_commands.json entries matching the scanned files,
   falling back gracefully when the database is absent or malformed.

2. cppcheck's information category (missing include paths, checker
   reports, normalization notes) is non-actionable by definition but was
   captured as findings. Classify information-severity records as
   non-actionable in the phase filter.

Verified against a C++17 rod-solver repo (114 files) where 47
information-level records and repeated missingInclude noise dissolved
after the fix; upstream test suite green (5818 passed, 3 skipped) with
new unit tests for the classifier, compile-db harvesting, and malformed
database handling.
citizenadam added a commit to citizenadam/desloppify that referenced this pull request Sep 3, 2026
@awdemos

awdemos commented Sep 12, 2026

Copy link
Copy Markdown

The core fix is sound and I verified the important part end-to-end: cppcheck information: records keep their severity prefix through parse_gnu (the parser only strips file:line), so _is_information_record is live production code — both information records dropped, real error/warning findings kept, and the header-suffix guard correctly spares a .cpp "is never used" entry. Malformed/absent compile_commands.json is handled gracefully (+3 tests pass).

Four things to address before merging:

  1. The body is inaccurate: it claims _cppcheck_include_args already existed and "derived -I dirs only from in-scope headers" — on main that function does not exist and cppcheck gets zero -I args. The function is new in this PR. Please correct the description.
  2. Unadvertised flag changes: --check-level=exhaustive requires cppcheck ≥2.16 — older distro cppcheck rejects it, so every batch errors and the detector yields zero findings (only reduced-coverage metadata) for those users. Also --language=c++ --std=c++17 is forced on .c files, and --inline-suppr is added. None of these are mentioned in the body; each needs justification or removal.
  3. Unadvertised _is_header_unused_diagnostic filter — also swallows unusedFunction "… is never used." findings located in headers. Over-suppression; at minimum disclose it.
  4. New ruff I001 import-sort error (likely red in CI). Nit: relative -I paths in the compile db are resolved without the entry's directory field.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants