Skip to content

Clear misc-const-correctness, fix a build break from #275, quiet four checks - #285

Merged
helly25 merged 2 commits into
mainfrom
clang_tidy_tail
Aug 9, 2026
Merged

Clear misc-const-correctness, fix a build break from #275, quiet four checks#285
helly25 merged 2 commits into
mainfrom
clang_tidy_tail

Conversation

@helly25

@helly25 helly25 commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Two commits. The second one is the important find.

1. misc-const-correctness — cleared

Closes out the check #275 could only half-finish. Two sites were real (a never-mutated loop std::string_view, a read-only std::string); the other 13 get NOLINTs naming why the check is wrong: parameters passed by non-const reference, and declarations whose const-ness would change the deduced type a neighbouring static_assert(...decltype(ref)...) checks.

2. A build break that #275 shipped to main

./mbo/container/limited_set_benchmark.h:134:11: error: cannot assign to variable 'item'
  with const-qualified type 'const std::size_t'

#275 made test and item const, but both are assigned. It reached main because bazel test //... skips manual targets, so nothing ever built the benchmark — my full-suite run reported 109/109 green while the benchmark was broken.

It only became visible now because #280 put those manual targets into the compile DB, so clang-tidy could finally see them.

Reverted, and CI now builds every clang-tidy-tagged manual target, so the next one cannot slip through the same way. Verified all five build.

Also: stop linting a file bazel does not build

tools/clang_tidy.sh now skips mbo/hash/measurements/smhasher3/. It is an SMHasher3 plugin compiled by that project's cmake, so clang-tidy was linting it with flags guessed from unrelated files and reporting its Platform.h / Hashlib.h includes as missing. Removes 4 spurious categories at once, including all 10 c-style-cast findings.

Four checks disabled, each with its reason in .clang-tidy

  • misc-no-recursion — recursion is the shape of the code it flags (Stringify walks nested structures, BigNumberLen recurses once for negatives), and it reports every member of a call chain, so one algorithm yields a cluster.
  • bugprone-std-namespace-modification — the namespace std blocks are specialisations of std templates for our own types, which is how those extension points are meant to be used.
  • cppcoreguidelines-avoid-magic-numbers / readability-magic-numbers (aliases) — they fire on test expectations and on the numeric tables that are the subject.

Test

  • misc-const-correctness reports zero.
  • All five clang-tidy-tagged manual targets build.
  • bazel test --config=clang //...109/109 pass.
  • pre-commit run -a green.

@helly25
helly25 requested a review from Fab-Cat August 9, 2026 20:06
@helly25
helly25 enabled auto-merge (squash) August 9, 2026 20:06
helly25 added 2 commits August 9, 2026 21:41
Two of the sites were real and are fixed:
  * stringify.h - a loop `std::string_view` that is never mutated, which
    STYLE_CPP.md now says should be const.
  * optional_data_or_ref_test.cc - a `std::string` only ever read.

The rest are the check being wrong, so they get a NOLINT naming why:
  * struct_names_clang.h (4) - `field_index` and `storage` are passed to
    FieldCount()/Init() by non-const reference and via `&storage.Get()`.
    #275 showed const there fails to compile.
  * optional_ref_test.cc, optional_data_or_ref_test.cc (9) - these
    declarations are the subject under test. const changes the deduced
    type a neighbouring `static_assert(...decltype(ref)...)` checks.

misc-const-correctness now reports zero.

Signed-off-by: helly25 <6420169+helly25@users.noreply.github.com>
#275 made `test` and `item` const in limited_set_benchmark.h, but both
are assigned:

  ./mbo/container/limited_set_benchmark.h:134:11: error: cannot assign to
  variable 'item' with const-qualified type 'const std::size_t'

It reached main because `bazel test //...` skips `manual` targets, so
nothing built the benchmark. Only #280 - which put those targets into the
compile DB - made clang-tidy able to see it. Reverted, and CI now builds
every clang-tidy-tagged manual target so the next one cannot slip through
the same way. All five build.

tools/clang_tidy.sh now skips mbo/hash/measurements/smhasher3/: bazel does
not build it (it is an SMHasher3 plugin compiled by that project's cmake),
so clang-tidy was linting it with flags guessed from unrelated files and
reporting its SMHasher3 includes as missing. That removes 4 spurious
categories at once, including all 10 c-style-cast findings.

Disabled, each with its reason recorded:
  * misc-no-recursion - recursion is the shape of the code it flags, and
    it reports every member of a call chain.
  * bugprone-std-namespace-modification - the `namespace std` blocks are
    specialisations of std templates for our own types.
  * cppcoreguidelines-avoid-magic-numbers / readability-magic-numbers
    (aliases) - they fire on test expectations and on the numeric tables
    that ARE the subject.

bazel test --config=clang //... - 109/109 pass.

Signed-off-by: helly25 <6420169+helly25@users.noreply.github.com>
@helly25 helly25 changed the title Clear misc-const-correctness Clear misc-const-correctness, fix a build break from #275, quiet four checks Aug 9, 2026
@helly25
helly25 merged commit 593fbd1 into main Aug 9, 2026
23 checks passed
@helly25
helly25 deleted the clang_tidy_tail branch August 9, 2026 21:24
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