Skip to content

Clear the three most concentrated clang-tidy checks - #272

Merged
helly25 merged 2 commits into
mainfrom
clang_tidy_fix_concentrated
Aug 8, 2026
Merged

Clear the three most concentrated clang-tidy checks#272
helly25 merged 2 commits into
mainfrom
clang_tidy_fix_concentrated

Conversation

@helly25

@helly25 helly25 commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Second of the clang-tidy triage PRs, independent of #271 (different files). Clears 80 of the 639 remaining findings.

Only one of the three turned out to be an actual defect. That is worth stating plainly, because "80 findings fixed" would otherwise overstate it.

google-build-explicit-make-pair — 32 findings, a real defect

mbo/strings/numbers.h used std::make_pair<uint32_t, unsigned>(...). Explicit template arguments pin the parameters to uint32_t&& / unsigned&&, defeating the deduction make_pair exists to provide. Now std::pair directly, as the diagnostic recommends.

performance-unnecessary-value-param — 25 findings, marginal

All 25 are one source location in mbo/container/any_scan.h, re-reported per template instantiation.

The motivation is not copy cost, and I checked rather than assumed:

  • MakeAnyScanData is 16 bytes — a single shared_ptr. A copy is one atomic increment.
  • By-value and const& compile to an identical parameter: both ptr in the IR. The type is not register-transportable, because shared_ptr is not trivially copyable. ([[clang::trivial_abi]] does force [2 x ptr], but clang simultaneously warns the attribute "cannot be applied" — an ABI hazard, so not an option.)
  • The const shared_ptr member means even a "move" copies, verified: after Data b{std::move(a)} the source still holds its pointer and use_count == 2.

So by-value buys nothing here; const& drops one atomic pair per construction. Real but tiny — this is tidiness, not performance. Happy to drop this hunk if you would rather not churn the signature.

readability-implicit-bool-conversion — 23 findings, not defects

  • diff_myers.cc (2): (d + lo) & 1 is an idiomatic parity test. Enabled AllowIntegerConditions / AllowPointerConditions, which is standard C++ style (if (ptr), if (n)) and clears these legitimately.
  • hash_differential_test.cc (21): a false positive. Inside the XXH64 / XXH3_* reference macros the check misattributes a conversion to the gtest << message chain — it points at the string literal "len: " and proposes replacing it with true. Suppressed with that rationale, extending the NOLINT region the file already uses.

Test

  • All three checks report zero findings on the affected files.
  • bazel test --config=clang //mbo/strings:all //mbo/container:any_scan_test //mbo/diff:all //mbo/hash:hash_differential_test — 9/9 pass.
  • pre-commit run -a green.

google-build-explicit-make-pair (32 findings, mbo/strings/numbers.h):
a real defect. `std::make_pair<uint32_t, unsigned>(...)` with explicit
template arguments pins the parameters to `uint32_t&&`/`unsigned&&`,
which defeats the deduction make_pair exists for. Use std::pair directly,
as the diagnostic says.

performance-unnecessary-value-param (25 findings, mbo/container/any_scan.h):
one source location, re-reported per template instantiation. Note the
motivation is NOT copy cost -- MakeAnyScanData is 16 bytes holding one
shared_ptr, so a copy is a single atomic increment, and by-value vs
const& compile to the identical indirect parameter (both `ptr` in IR;
the type is not register-transportable because shared_ptr is not
trivially copyable). By-value simply buys nothing here: the const
shared_ptr member means even a "move" copies. const& drops one atomic
pair per construction.

readability-implicit-bool-conversion (23 findings): not defects.
  * diff_myers.cc: `(d + lo) & 1` is an idiomatic parity test. Allow
    integer and pointer conditions via check options, which is standard
    C++ style and clears these legitimately.
  * hash_differential_test.cc: inside the XXH64 / XXH3_* reference
    macros the check misattributes a conversion to the gtest `<<`
    message chain -- it points at string literals like "len: " and
    proposes replacing them with `true`. Suppressed with a rationale,
    extending the NOLINT region the file already uses.

All three checks now report zero. Tests pass across the touched
packages (9/9).

Signed-off-by: helly25 <6420169+helly25@users.noreply.github.com>
@helly25
helly25 requested a review from Fab-Cat August 8, 2026 17:11
@helly25
helly25 enabled auto-merge (squash) August 8, 2026 17:12
@helly25
helly25 merged commit e9d49ff into main Aug 8, 2026
23 checks passed
@helly25
helly25 deleted the clang_tidy_fix_concentrated branch August 8, 2026 18:12
helly25 added a commit that referenced this pull request Aug 9, 2026
#272 changed AnyScanImpl's constructors to take MakeAnyScanData by const
reference. That silently broke the three public wrappers - AnyScan,
ConstScan and ConvertingScan - which take the same type BY VALUE and then
`std::move(data)` into AnyScanImpl. Moving into a const& parameter is a
no-op, so those moves became misleading dead code and the by-value
parameters became "copied but only used as a const reference".

The finding count went from 25 (at the impl constructor) to 45 (at the
three wrappers): my verification for #272 confirmed the specific
diagnostic cleared without re-measuring the file, so the regression went
unnoticed.

Make the three wrappers take a const reference too and drop the pointless
`std::move`. That is consistent with the type: 16 bytes holding one const
shared_ptr, whose const member makes even a move a copy.

performance-unnecessary-value-param now reports zero for the header.
bazel test --config=clang //... - 109/109 pass.

Signed-off-by: helly25 <6420169+helly25@users.noreply.github.com>
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