Skip to content

clang-tidy: check and fix cppcoreguidelines-pro-bounds-array-to-pointer-decay#3074

Open
prashsti29 wants to merge 5 commits intopgRouting:developfrom
prashsti29:prashsti29-clang-tidy
Open

clang-tidy: check and fix cppcoreguidelines-pro-bounds-array-to-pointer-decay#3074
prashsti29 wants to merge 5 commits intopgRouting:developfrom
prashsti29:prashsti29-clang-tidy

Conversation

@prashsti29
Copy link

@prashsti29 prashsti29 commented Feb 20, 2026

Summary:

  • Enable cppcoreguidelines-pro-bounds-array-to-pointer-decay in .clang-tidy.
  • Fixed warnings related to implicit array-to-pointer decay.

Changes Made:

  • Fixed implicit array-to-pointer decay in src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp by replacing const char c_err_msg[] with const std::string c_err_msg.
  • Fixed implicit array-to-pointer decay in src/common/assert.cpp by adding an explicit static_cast<void**> when passing trace[] to backtrace() and backtrace_symbols().

Summary by CodeRabbit

  • Refactor

    • Minor internal updates to improve stability and modernize error handling.
  • Chores

    • Enabled an additional static analysis check to strengthen code quality.
    • Added a CI trigger file to ensure continuous integration runs on changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

Walkthrough

Enables the clang-tidy check cppcoreguidelines-pro-bounds-array-to-pointer-decay, changes a local C-style string to std::string in the breadth-first search driver, and adds an explicit static_cast<void**> when calling backtrace APIs; also adds a .ci-trigger file.

Changes

Cohort / File(s) Summary
Configuration
.clang-tidy
Removed exclusion for cppcoreguidelines-pro-bounds-array-to-pointer-decay, enabling that clang-tidy check.
Breadth-first search driver
src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cpp
Replaced local const char c_err_msg[] with const std::string c_err_msg (no control-flow change).
Backtrace utility
src/common/assert.cpp
Call sites for backtrace/backtrace_symbols now pass the trace buffer via static_cast<void**> to match expected pointer type.
CI trigger
.ci-trigger
Added a file containing trigger CI to signal CI runs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

Enhancement, C/C++

Suggested reviewers

  • cvvergara
  • robe2

Poem

🐰 A tiny tweak, a tidy cheer,
Casts and strings hop into gear,
CI nudged awake with a wink,
Clean checks humming, code in sync,
Carrots for warnings—happy year! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: enabling a clang-tidy check and fixing associated warnings in the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/common/assert.cpp`:
- Around line 47-48: Replace the explicit static_cast<void**>(trace) uses with
the C++17 idiomatic std::data(trace) when calling backtrace and
backtrace_symbols: update the calls that reference trace
(trace_size/backtrace/backtrace_symbols) to pass std::data(trace) instead of
static_cast, and add the proper include for std::data (e.g., `#include`
<iterator>) so the code compiles.

Comment on lines +47 to +48
trace_size = backtrace(static_cast<void**>(trace), 16);
char** funcNames = backtrace_symbols(static_cast<void**>(trace), trace_size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider std::data(trace) as a cleaner alternative to static_cast<void**>(trace).

An LLVM bug report on the same backtrace_symbols pattern confirms that static_cast<void**> resolves the array-to-pointer decay warning, so the fix is correct. However, the idiomatic C++17 way to explicitly obtain a pointer to an array's first element without a cast is std::data():

♻️ Optional refactor using `std::data()`
-        trace_size = backtrace(static_cast<void**>(trace), 16);
-        char** funcNames = backtrace_symbols(static_cast<void**>(trace), trace_size);
+        trace_size = backtrace(std::data(trace), 16);
+        char** funcNames = backtrace_symbols(std::data(trace), trace_size);

Both approaches silence the clang-tidy check because the check was patched to not flag explicit casts. The std::data() form expresses the intent (pointer to the first element) more directly than a static_cast.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
trace_size = backtrace(static_cast<void**>(trace), 16);
char** funcNames = backtrace_symbols(static_cast<void**>(trace), trace_size);
trace_size = backtrace(std::data(trace), 16);
char** funcNames = backtrace_symbols(std::data(trace), trace_size);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/common/assert.cpp` around lines 47 - 48, Replace the explicit
static_cast<void**>(trace) uses with the C++17 idiomatic std::data(trace) when
calling backtrace and backtrace_symbols: update the calls that reference trace
(trace_size/backtrace/backtrace_symbols) to pass std::data(trace) instead of
static_cast, and add the proper include for std::data (e.g., `#include`
<iterator>) so the code compiles.

@cvvergara cvvergara marked this pull request as draft February 21, 2026 00:19
@cvvergara
Copy link
Member

You don't have your actions running

@prashsti29 prashsti29 marked this pull request as ready for review February 21, 2026 02:34
@cvvergara cvvergara marked this pull request as draft March 1, 2026 17:43
Copy link
Member

@cvvergara cvvergara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see your actions running

@prashsti29 prashsti29 marked this pull request as ready for review March 2, 2026 14:19
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.ci-trigger:
- Line 1: Remove the temporary CI trigger file named .ci-trigger from the
repository before merging; delete the file and any references to it (there are
no code symbols to change) so the commit does not include this workaround, and
rely on proper GitHub Actions workflow configuration or the workflow re-run
button instead.

ℹ️ Review info

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between edae3d3 and 8e11980.

📒 Files selected for processing (1)
  • .ci-trigger

.ci-trigger Outdated
@@ -0,0 +1 @@
trigger CI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove this CI trigger file before merging.

This file appears to be a workaround to force GitHub Actions to run (per the maintainer's comment about actions not running). It serves no functional purpose in the repository and should be removed before merging to avoid permanent clutter.

Consider using GitHub's workflow re-run button or fixing the underlying CI trigger configuration instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.ci-trigger at line 1, Remove the temporary CI trigger file named
.ci-trigger from the repository before merging; delete the file and any
references to it (there are no code symbols to change) so the commit does not
include this workaround, and rely on proper GitHub Actions workflow
configuration or the workflow re-run button instead.

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