Skip to content

Lint & CI: cppcheck, IWYU, cast/linkage warnings#17

Merged
kahrendt merged 5 commits into
mainfrom
lint-ci-tooling
Jul 7, 2026
Merged

Lint & CI: cppcheck, IWYU, cast/linkage warnings#17
kahrendt merged 5 commits into
mainfrom
lint-ci-tooling

Conversation

@kahrendt

@kahrendt kahrendt commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Tooling and static-analysis pass bringing the repo in line with the other microCodec projects. Adds whole-program and include analysis to CI, tightens the first-party warning set, and fixes the handful of findings each check surfaced. No decoder logic changes; the forked src/tremor and demuxer submodule stay excluded from the new checks.

  • Adds cppcheck whole-program analysis: script/cppcheck.sh + CI job run unusedFunction across all first-party sources in one pass. Fixes its two findings in the benchmark example (default-init TaskParams, replace a C-style void* cast).
  • Enforces static internal linkage and no-discard decode(): add -Wmissing-prototypes/-Wmissing-declarations so any non-header function must be static (keeps -Wunused-function effective); mark the three vorbis_to_wav helpers static. Mark decode() MICRO_VORBIS_NODISCARD so ignoring the decoder's only error channel warns at every call site.
  • Bans C-style casts with -Wold-style-cast: catches value casts cppcheck's cstyleCast misses; converts the three (int32_t) bitrate casts in vorbis_header.cpp. The forked tremor include dir becomes SYSTEM so its C-style casts don't leak into first-party compiles.
  • Adds include-what-you-use checking: script/check-includes.sh runs clang-include-cleaner over every source/header in a host pass and an ESP pass (with stub ESP-IDF headers from esp_stubs.py) so guarded ESP32 branches are analyzed without a cross toolchain. Fixes a transitive-include reliance in ogg_vorbis_decoder.cpp and missing includes in the benchmark.
  • Lint & CI cleanup: honor a pre-set $CLANG_TIDY (CI pins clang-tidy-18) and pass --warnings-as-errors; scan the whole src dir in cppcheck; build a pinned cppcheck 2.21.0 from source; adopt the canonical gather_files engine in check_includes.py; bump stale action pins; label .clang-tidy as C++14.

kahrendt added 5 commits July 7, 2026 13:00
cppcheck's unusedFunction check sees every first-party source in one
pass, so it can flag functions with no caller anywhere in the project,
which the per-TU clang-tidy pass cannot. Fix its two findings in the
benchmark example: default-initialize TaskParams members and replace a
C-style cast from void* with static_cast.
Add -Wmissing-prototypes (clang) / -Wmissing-declarations (GCC) to the
first-party warning sets: any function not declared in a header must be
static, which keeps -Wunused-function able to see dead internal
functions. Mark the three vorbis_to_wav helpers it flagged static.

Mark decode() MICRO_VORBIS_NODISCARD ([[nodiscard]] at C++17, GNU
warn_unused_result at C++14) so silently ignoring the decoder's only
error channel warns at every call site.
cppcheck's cstyleCast check only flags casts to pointer or reference
types; the compiler flag catches value casts too. Convert the three
(int32_t) bitrate casts in vorbis_header.cpp it found. The forked
tremor include directory becomes SYSTEM so headers shared with the C
sources don't leak their C-style casts into first-party compiles --
the header-side counterpart of the existing -w suppression.
script/check-includes.sh runs clang-include-cleaner over every source and
header in two passes: a host pass, and an ESP pass with -DESP_PLATFORM plus
stub ESP-IDF headers (materialized from script/esp_stubs.py) so guarded
ESP32 branches are analyzed without a cross toolchain. A foo.cpp may rely
on its matching header's direct includes; IWYU pragmas are honored. The
forked src/tremor decoder and lib/micro-ogg-demuxer submodule are
excluded, mirroring cppcheck.

Fixes it surfaced: ogg_vorbis_decoder.cpp used ogg_int32_t via a
transitive include (now includes <ogg/os_types.h>); decode_benchmark
called esp_get_free_heap_size() without esp_system.h and was missing
<cstdint>.
Bring the tooling in line with other microCodec projects.

- clang-tidy.sh: honor a pre-set $CLANG_TIDY (CI pins clang-tidy-18) instead
  of unconditionally clobbering it, validate the binary up front, and pass
  --warnings-as-errors='*' on both the main and tests passes.
- ci.yml lint job: export CLANG_TIDY=clang-tidy-18 so the pin takes effect.
- cppcheck.sh: scan the src directory instead of a hand-listed file set
  (the src/tremor suppression already fences off the vendored fork).
- ci.yml cppcheck job: build a pinned cppcheck 2.21.0 from source with a
  cache step, replacing the lagging apt package.
- check_includes.py: adopt the canonical gather_files(dirs, prune=()) engine.
- Bump stale action pins: cache v6.1.0, setup-python v6.3.0, drafter v7.5.1.
- release-drafter: force-major/force-minor labels and strict permissions: {}.
- .clang-tidy: label the header C++14 (matches the actual build standard in
  cmake/host.cmake and the library's own C++14 baseline), not C++11.
- .gitignore: record .conventions-version as a local-only marker.
@kahrendt kahrendt enabled auto-merge (squash) July 7, 2026 17:04
@kahrendt kahrendt merged commit 290c2b4 into main Jul 7, 2026
12 checks passed
@kahrendt kahrendt deleted the lint-ci-tooling branch July 7, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant