Skip to content

fix(clang-tidy): re-enable bugprone-assignment-in-if-condition#12552

Open
vish0012 wants to merge 2 commits intoautowarefoundation:mainfrom
vish0012:fix/clang-tidy-assignment-in-if-condition
Open

fix(clang-tidy): re-enable bugprone-assignment-in-if-condition#12552
vish0012 wants to merge 2 commits intoautowarefoundation:mainfrom
vish0012:fix/clang-tidy-assignment-in-if-condition

Conversation

@vish0012
Copy link
Copy Markdown
Contributor

@vish0012 vish0012 commented May 7, 2026

Description

Re-enables bugprone-assignment-in-if-condition in .clang-tidy-ci.

The check was suppressed in #12431 with 45 errors across two files. This PR addresses both affected packages from the issue list.

Refs #12450

Approach

Both flagged files are derived from upstream third-party code where the assignment-in-condition pattern is intentional. Rather than refactoring 45 sites and diverging from the upstream reference implementations, this PR adds per-line // NOLINTNEXTLINE(bugprone-assignment-in-if-condition) markers.

I used NOLINTNEXTLINE instead of NOLINTBEGIN / NOLINTEND because the Autoware pre-commit/cpplint pipeline does not accept the block syntax.

planning/autoware_freespace_planning_algorithms/src/reeds_shepp.cpp — 39 sites

This file is derived from OMPL's Reeds-Shepp implementation. The assignment-in-condition pattern is intentional: each path family computes a candidate path length L and compares it against L_min in the same expression.

Example pattern:

if (LpSpLp(x, y, phi, t, u, v) && L_min > (L = std::abs(t) + std::abs(u) + std::abs(v))) {

These patterns are repeated across path families with time-flip, reflect, and time-flip+reflect variants. Refactoring all 39 sites would make the file diverge from the OMPL reference and make future cross-checking harder.

perception/autoware_bytetrack/lib/src/lapjv.cpp — 6 sites

This file is part of the LAPJV / ByteTrack code. All 6 reported sites are expansions of the NEW(x, t, n) macro defined in lapjv.h.

The macro uses the canonical malloc-or-bail idiom:

if ((x = malloc(...)) == 0) return -1;

The assignment is intentional here. The NOLINTNEXTLINE comments are placed at the call sites in lapjv.cpp because these are the locations reported by clang-tidy.

How to reproduce

From the colcon workspace root:

cd ~/autoware_clang_tidy
source /opt/ros/humble/setup.bash

mkdir -p /tmp/clang-tidy-result

colcon build --packages-up-to autoware_freespace_planning_algorithms autoware_bytetrack \
  --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=1

for PKG in autoware_freespace_planning_algorithms autoware_bytetrack; do
  echo "=== ${PKG} ==="
  run-clang-tidy -p build/ \
    -config="$(cat src/autoware_universe/.clang-tidy-ci)" \
    -header-filter=".*${PKG}.*" \
    -j $(nproc) "${PKG}" \
    > /tmp/clang-tidy-result/${PKG}.log 2>&1

  echo "assignment-in-if errors: $(grep -E 'bugprone-assignment-in-if-condition' /tmp/clang-tidy-result/${PKG}.log | grep 'error:' | wc -l)"
done

Verification

Reproduced the original errors locally with clang-tidy-18, then confirmed both affected packages return 0 errors after the fix.

Result:

=== autoware_freespace_planning_algorithms ===
assignment-in-if errors: 0
=== autoware_bytetrack ===
assignment-in-if errors: 0

Notes

No local-only include-path workarounds are included in this PR. The only .clang-tidy-ci change is removing the suppression line:

-  -bugprone-assignment-in-if-condition,

Add NOLINTNEXTLINE markers to the 45 sites flagged by
bugprone-assignment-in-if-condition and re-enable the check in
.clang-tidy-ci.

Both files are derived from upstream third-party code where the
assignment-in-if pattern is intentional:

- planning/autoware_freespace_planning_algorithms/src/reeds_shepp.cpp
  is derived from OMPL's ReedsSheppStateSpace.cpp (BSD). Each path
  family computes a candidate length L and compares it against L_min
  in the same expression; rewriting all 39 sites would diverge from
  the OMPL upstream and make future cross-checking harder.

- perception/autoware_bytetrack/lib/src/lapjv.cpp is the upstream
  LAPJV port (MIT, Yifu Zhang). The 6 sites are all expansions of
  the NEW(x, t, n) macro from lapjv.h, which uses the canonical
  malloc-or-bail idiom 'if ((x = malloc(...)) == 0) return -1;'.

Refs: autowarefoundation#12450
Signed-off-by: Vishal Chauhan <40782713+vish0012@users.noreply.github.com>
@vish0012 vish0012 requested a review from mitsudome-r May 7, 2026 05:30
@github-actions github-actions Bot added component:perception Advanced sensor data processing and environment understanding. (auto-assigned) component:planning Route planning, decision-making, and navigation. (auto-assigned) labels May 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

@vish0012 vish0012 added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label May 7, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33.13%. Comparing base (b1df772) to head (95ab20f).

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #12552       +/-   ##
===========================================
+ Coverage   18.65%   33.13%   +14.47%     
===========================================
  Files        1917      175     -1742     
  Lines      131368    23658   -107710     
  Branches    44506    12306    -32200     
===========================================
- Hits        24501     7838    -16663     
+ Misses      86756     8206    -78550     
+ Partials    20111     7614    -12497     
Flag Coverage Δ
daily ?
full-suite 33.13% <ø> (+14.48%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

component:perception Advanced sensor data processing and environment understanding. (auto-assigned) component:planning Route planning, decision-making, and navigation. (auto-assigned) run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci)

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

1 participant