-
-
Notifications
You must be signed in to change notification settings - Fork 383
Add cppcoreguidelines-init-variables check and fix warnings #3013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request enforces stricter variable initialization practices by enabling the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
.clang-tidysrc/dijkstra/dijkstra_driver.cpp
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-04-29T18:59:06.824Z
Learnt from: cvvergara
Repo: pgRouting/pgrouting PR: 2879
File: sql/dijkstra/dijkstra.sql:56-57
Timestamp: 2025-04-29T18:59:06.824Z
Learning: The maintainer prefers not to add inline comments to internal function calls like _pgr_dijkstra, even when they contain multiple boolean and numeric flags.
Applied to files:
src/dijkstra/dijkstra_driver.cpp
📚 Learning: 2025-02-27T23:05:28.589Z
Learnt from: cvvergara
Repo: pgRouting/pgrouting PR: 2771
File: sql/common/_checkquery.sql:33-33
Timestamp: 2025-02-27T23:05:28.589Z
Learning: When reviewing PostgreSQL/pgRouting code, respect the maintainer's preference for brevity over additional comments when variable names are descriptive.
Applied to files:
src/dijkstra/dijkstra_driver.cpp
📚 Learning: 2025-04-25T00:59:52.580Z
Learnt from: cvvergara
Repo: pgRouting/pgrouting PR: 2868
File: src/contraction/contractionHierarchies_driver.cpp:47-56
Timestamp: 2025-04-25T00:59:52.580Z
Learning: In pgRouting, driver functions like `pgr_contractionHierarchies` assume that callers within the project will pass valid non-null pointers, as these functions are only used internally with well-defined call patterns. Null checks on the pointers themselves (as opposed to their dereferenced values) are considered unnecessary since the caller is guaranteed to pass references to variables.
Applied to files:
src/dijkstra/dijkstra_driver.cpp
🧬 Code graph analysis (1)
src/dijkstra/dijkstra_driver.cpp (1)
include/dijkstra/dijkstra.hpp (6)
dijkstra(120-148)dijkstra(120-125)dijkstra(157-170)dijkstra(157-161)dijkstra(174-188)dijkstra(174-178)
🪛 Cppcheck (2.19.0)
src/dijkstra/dijkstra_driver.cpp
[style] 169-169: The function 'examine_edge' is never used.
(unusedFunction)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
.clang-tidy (1)
9-10: LGTM! Good addition of initialization safety check.Enabling
cppcoreguidelines-init-variableshelps prevent uninitialized variable bugs by enforcing initialization at declaration time.src/dijkstra/dijkstra_driver.cpp (2)
168-168: Good use of value initialization.The explicit braced initialization
{}is good modern C++ practice and clearly communicates intent.
172-172: Good use of value initialization.Consistent with the directed graph initialization above. The explicit braced initialization clearly communicates intent.
| size_t n{0}; | ||
| n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Consider combining into single-step initialization.
The two-step initialization (declare with 0, then immediately assign) satisfies the clang-tidy rule but is not idiomatic. The initial value is never used.
🔎 Suggested single-step initialization
-size_t n{0};
-n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
+size_t n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);Or with braced initialization:
-size_t n{0};
-n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals);
+size_t n{(n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals)};📝 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.
| size_t n{0}; | |
| n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals); | |
| size_t n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals); |
| size_t n{0}; | |
| n = (n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals); | |
| size_t n{(n_goals <= 0) ? (std::numeric_limits<size_t>::max)() : static_cast<size_t>(n_goals)}; |
🤖 Prompt for AI Agents
In src/dijkstra/dijkstra_driver.cpp around lines 164-165, combine the two-step
declare-and-assign into a single initialization: replace the separate
declaration and assignment with one line that initializes n from the
conditional, e.g. using either classic or braced initialization: size_t n =
(n_goals <= 0) ? std::numeric_limits<size_t>::max() :
static_cast<size_t>(n_goals); or size_t n{ (n_goals <= 0) ?
std::numeric_limits<size_t>::max() : static_cast<size_t>(n_goals) }; ensure you
keep the explicit cast for n_goals and call numeric_limits::max() normally.
cvvergara
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I compiled locally using:
CXX=clang++ CC=clang cmake -DUSE_CLANG_TIDY=ON -DBUILD_HTML=OFF -DPOSTGRESQL_BIN=${PGBIN} ..
and these are some of the many warnings I get that are not fixed,
[ 20%] Building CXX object src/trsp/CMakeFiles/trsp.dir/trsp_driver.cpp.o
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:185:15: warning: variable 'inserted' is not initialized [cppcoreguidelines-init-variables]
185 | bool inserted;
| ^
| = false
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:398:14: warning: variable 'found_e' is not initialized [cppcoreguidelines-init-variables]
398 | bool found_e;
| ^
| = false
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:426:18: warning: variable 'inserted' is not initialized [cppcoreguidelines-init-variables]
426 | bool inserted;
| ^
| = false
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:437:17: warning: variable 'p_max' is not initialized [cppcoreguidelines-init-variables]
437 | int64_t p_max;
| ^
| = 0
/home/vicky/pgrouting/pgrouting/cvvergara/include/contraction/contractionGraph.hpp:439:14: warning: variable 'found_e' is not initialized [cppcoreguidelines-init-variables]
439 | bool found_e;
| ^
| = false
Please fix
the files under max_flow directory
Fixes # .
Changes proposed in this pull request:
@pgRouting/admins
Summary by CodeRabbit
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.