Skip to content

Conversation

@Mohit242-bit
Copy link
Contributor

@Mohit242-bit Mohit242-bit commented Feb 8, 2026

Fixes #3041

Summary

  • Enable cppcoreguidelines-use-default-member-init in .clang-tidy.
  • Refactor initialization in these classes to use default member initializers:
    • Pgr_bdAstar
    • PgrDirectedChPPGraph
    • Pgr_contractionGraph
    • Pgr_bidirectional
    • dijkstra_distance_visitor_no_init
    • Solution
    • Pgr_ksp

Changes proposed in this pull request

  • Update .clang-tidy to enable cppcoreguidelines-use-default-member-init.
  • Refactor constructor initializations as per the guideline for the classes above.
  • Run clang-tidy and ensure no violations remain for this check.
  • All tests and builds pass locally with the new code style.

@pgRouting/admins

Summary by CodeRabbit

  • Refactor
    • Standardized default value handling across the codebase by moving many initializations into member declarations.
    • Removed one now-unneeded internal member and simplified constructors accordingly.
    • Internal cleanup only — no changes to user-facing behavior or public interfaces.

- 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
Copilot AI review requested due to automatic review settings February 8, 2026 16:07
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

Walkthrough

Enabled the cppcoreguidelines-use-default-member-init clang-tidy check and updated multiple classes to move member initializers from constructor initializer lists into in-class default member initializers; also removed the EPSILON member from the VRP Solution class.

Changes

Cohort / File(s) Summary
Clang-tidy config
/.clang-tidy
Removed exclusion for cppcoreguidelines-use-default-member-init, enabling the check.
bdAstar
include/bdAstar/bdAstar.hpp
Moved m_heuristic and m_factor initialization from constructor to in-class defaults.
Chinese Postman
include/chinese/chinesePostman.hpp
Added in-class defaults for totalDeg{0} and totalCost{0} (previously constructor-initialized).
Contraction Graph
include/contraction/contractionGraph.hpp
Added in-class default min_edge_id{0} instead of constructor initializer.
Bidirectional search
include/cpp_common/bidirectional.hpp
Moved best_cost initialization to in-class default (best_cost{0}).
Dijkstra visitors
include/visitors/dijkstra_visitors.hpp
Moved m_num_examined initialization to in-class default (m_num_examined{0}).
VRP solution
include/vrp/solution.hpp, src/pickDeliver/solution.cpp
Removed protected EPSILON member and removed its constructor initialization.
Yen K-shortest paths
include/yen/ksp.hpp
Added in-class defaults for m_start{0}, m_end{0}, m_K{0}, m_heap_paths{false} and removed those initializers from the constructor.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Enhancement, C/C++

Suggested reviewers

  • cvvergara
  • robe2

Poem

🐇 I nibble defaults in the code so neat,
I tuck them into members, soft and sweet.
Constructors breathe easier, calm and light,
Defaults snugly guard them through the night.
Hooray — a tidy hop, all set just right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of enabling and fixing the cppcoreguidelines-use-default-member-init clang-tidy check.
Linked Issues check ✅ Passed All code changes align with issue #3041: the cppcoreguidelines-use-default-member-init check is enabled in .clang-tidy, and violations are fixed across multiple classes.
Out of Scope Changes check ✅ Passed All changes are directly scoped to enabling and fixing the cppcoreguidelines-use-default-member-init check; no unrelated modifications are present.

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

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

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.

❤️ 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

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 | 🟠 Major

Copy assignment operator no longer copies EPSILON — behavioral change.

The AI summary indicates that EPSILON = sol.EPSILON was previously present in this operator body and has been removed. If EPSILON is ever modified after construction (it's a non-const, non-static protected member, so subclasses can modify it), the copy assignment will silently drop that change.

If EPSILON is truly immutable, this is harmless but the type should reflect that (see the static constexpr suggestion 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).

Copy link

Copilot AI left a 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-init by 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.

@Mohit242-bit Mohit242-bit force-pushed the fix/cppcoreguidelines-use-default-member-init branch from fe441bc to 793a3e5 Compare February 8, 2026 16:18
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

🤖 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
@Mohit242-bit Mohit242-bit force-pushed the fix/cppcoreguidelines-use-default-member-init branch from 793a3e5 to 3a3f458 Compare February 8, 2026 16:20
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.

Check and fix cppcoreguidelines-use-default-member-init

1 participant