clang-tidy: check and fix cppcoreguidelines-use-default-member-init#3065
clang-tidy: check and fix cppcoreguidelines-use-default-member-init#3065Mohit242-bit wants to merge 1 commit intopgRouting:developfrom
Conversation
WalkthroughRemoved the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
include/vrp/solution.hpp (1)
74-78:⚠️ Potential issue | 🟠 MajorCopy assignment operator no longer copies
EPSILON— behavioral change.The AI summary indicates that
EPSILON = sol.EPSILONwas previously present in this operator body and has been removed. IfEPSILONis ever modified after construction (it's a non-const, non-staticprotectedmember, so subclasses can modify it), the copy assignment will silently drop that change.If
EPSILONis truly immutable, this is harmless but the type should reflect that (see thestatic constexprsuggestion above). If it can vary per instance, it must be copied here:🐛 Proposed fix if EPSILON can vary per instance
Solution& operator = (const Solution& sol) { + EPSILON = sol.EPSILON; fleet = sol.fleet; trucks = sol.trucks; return *this; };
🤖 Fix all issues with AI agents
In `@include/vrp/solution.hpp`:
- Line 49: EPSILON is declared as a non-const instance member; change it to a
compile-time constant by replacing the instance field with a static constexpr
double (e.g., static constexpr double EPSILON = 0.0001;) in the same scope
(class/namespace) so there is one immutable value shared across all instances;
update any code that relied on an instance pointer/reference to EPSILON to
access it as a static member (ClassName::EPSILON or simply EPSILON if in the
same namespace/scope).
There was a problem hiding this comment.
Pull request overview
Enables the cppcoreguidelines-use-default-member-init clang-tidy check and updates several C++ classes to use in-class default member initializers instead of constructor initializer lists, aligning the codebase with the guideline.
Changes:
- Enable
cppcoreguidelines-use-default-member-initby updating.clang-tidy. - Refactor multiple classes/structs to use default member initializers (removing redundant constructor initializations).
- Simplify constructors accordingly across affected components (VRP, Yen KSP, bidirectional search, contraction, Chinese Postman, visitors).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
.clang-tidy |
Enables cppcoreguidelines-use-default-member-init by no longer excluding it. |
include/bdAstar/bdAstar.hpp |
Moves m_heuristic/m_factor to in-class initializers and simplifies ctor. |
include/chinese/chinesePostman.hpp |
Moves totalDeg/totalCost to in-class initializers and removes redundant ctor init. |
include/contraction/contractionGraph.hpp |
Moves min_edge_id to an in-class initializer and simplifies ctor. |
include/cpp_common/bidirectional.hpp |
Moves best_cost to an in-class initializer and removes redundant ctor init. |
include/visitors/dijkstra_visitors.hpp |
Moves m_num_examined to an in-class initializer and removes redundant ctor init. |
include/vrp/solution.hpp |
Moves EPSILON to an in-class initializer and removes redundant ctor/copy ctor/assignment initialization. |
include/yen/ksp.hpp |
Moves scalar members to in-class initializers and simplifies ctor initializer list. |
src/pickDeliver/solution.cpp |
Removes redundant EPSILON initialization from Solution constructor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fe441bc to
793a3e5
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@include/vrp/solution.hpp`:
- Around line 48-49: In class Solution fix the indentation of the access
specifier so it is indented one space inside the class (change the line with
"protected:" so it aligns with other class members), e.g. ensure "protected:"
sits at the same column as member declarations like
"std::deque<Vehicle_pickDeliver> fleet;" to satisfy CI whitespace rules.
793a3e5 to
3a3f458
Compare
3a3f458 to
45b0a21
Compare
There was a problem hiding this comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@include/vrp/solution.hpp`:
- Line 49: Replace the mutable instance-scope constant declaration "double
EPSILON{0.0001};" with a compile-time constant by declaring "static constexpr
double EPSILON = 0.0001;" so EPSILON is immutable and has internal
linkage/compile-time evaluation; update any usage sites to access EPSILON
directly (or via ClassName::EPSILON if it was inside a class) and remove any
separate out-of-class definitions or initializations if present.
|
Hii @cvvergara , I have resolved the conflicts with the develop branch and and solved the remaining errors. Its ready to merge now . Would appreciate a review when you get a chance |
Fixes #3041
Summary
cppcoreguidelines-use-default-member-initin.clang-tidy.Pgr_bdAstarPgrDirectedChPPGraphPgr_contractionGraphPgr_bidirectionaldijkstra_distance_visitor_no_initSolutionPgr_kspChanges proposed in this pull request
.clang-tidyto enablecppcoreguidelines-use-default-member-init.@pgRouting/admins
Summary by CodeRabbit
Refactor
Chore