clang-tidy: check and fix cppcoreguidelines-pro-bounds-array-to-pointer-decay#3074
clang-tidy: check and fix cppcoreguidelines-pro-bounds-array-to-pointer-decay#3074prashsti29 wants to merge 5 commits intopgRouting:developfrom
Conversation
WalkthroughEnables the clang-tidy check Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
| trace_size = backtrace(static_cast<void**>(trace), 16); | ||
| char** funcNames = backtrace_symbols(static_cast<void**>(trace), trace_size); |
There was a problem hiding this comment.
🧹 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.
| 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.
|
You don't have your actions running |
cvvergara
left a comment
There was a problem hiding this comment.
I dont see your actions running
There was a problem hiding this comment.
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.
.ci-trigger
Outdated
| @@ -0,0 +1 @@ | |||
| trigger CI | |||
There was a problem hiding this comment.
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.
Summary:
cppcoreguidelines-pro-bounds-array-to-pointer-decayin.clang-tidy.Changes Made:
src/breadthFirstSearch/binaryBreadthFirstSearch_driver.cppby replacingconst char c_err_msg[]withconst std::string c_err_msg.src/common/assert.cppby adding an explicitstatic_cast<void**>when passingtrace[]tobacktrace()andbacktrace_symbols().Summary by CodeRabbit
Refactor
Chores