-
-
Notifications
You must be signed in to change notification settings - Fork 388
clang-tidy: check and fix cppcoreguidelines-use-default-member-init #3065
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?
clang-tidy: check and fix cppcoreguidelines-use-default-member-init #3065
Conversation
- Enable cppcoreguidelines-use-default-member-init check in .clang-tidy - Use default member initializers instead of constructor initialization for: Pgr_bdAstar, PgrDirectedChPPGraph, Pgr_contractionGraph, Pgr_bidirectional, dijkstra_distance_visitor_no_init, Solution, Pgr_ksp Fixes pgRouting#3041
WalkthroughEnabled 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)
No actionable comments were generated in the recent review. 🎉 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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
- Enable cppcoreguidelines-use-default-member-init check in .clang-tidy - Use default member initializers instead of constructor initialization for: Pgr_bdAstar, PgrDirectedChPPGraph, Pgr_contractionGraph, Pgr_bidirectional, dijkstra_distance_visitor_no_init, Solution, Pgr_ksp Fixes pgRouting#3041 # Conflicts: # include/vrp/solution.hpp
793a3e5 to
3a3f458
Compare
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