Skip to content

clang-tidy: check and fix cppcoreguidelines-use-default-member-init#3065

Open
Mohit242-bit wants to merge 1 commit intopgRouting:developfrom
Mohit242-bit:fix/cppcoreguidelines-use-default-member-init
Open

clang-tidy: check and fix cppcoreguidelines-use-default-member-init#3065
Mohit242-bit wants to merge 1 commit intopgRouting:developfrom
Mohit242-bit:fix/cppcoreguidelines-use-default-member-init

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 by moving many initializations into member declarations and simplifying constructors.
    • Internal cleanup only — no changes to public interfaces or user-facing behavior.
  • Chore

    • Adjusted lint/config checks (internal) with one rule removed.

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

Removed the cppcoreguidelines-use-default-member-init rule from .clang-tidy and moved many members' constructor initializers into in-class default initializers across several headers; EPSILON in the VRP Solution class was default-initialized in-class and corresponding constructor/assignment explicit resets were removed.

Changes

Cohort / File(s) Summary
Clang-tidy config
/.clang-tidy
Removed cppcoreguidelines-use-default-member-init from the Checks list.
Header member defaulting
include/bdAstar/bdAstar.hpp, include/chinese/chinesePostman.hpp, include/contraction/contractionGraph.hpp, include/cpp_common/bidirectional.hpp, include/visitors/dijkstra_visitors.hpp, include/yen/ksp.hpp
Moved various member initializations from constructor initializer lists into in-class default member initializers (e.g., m_heuristic{5}, m_factor{1.0}, totalDeg{0}, totalCost{0}, min_edge_id{0}, best_cost{0}, m_num_examined{0}, m_start{0}, m_end{0}, m_K{0}, m_heap_paths{false}).
VRP Solution & usage
include/vrp/solution.hpp, src/pickDeliver/solution.cpp
Changed EPSILON to an in-class default (double EPSILON{0.0001};) and removed explicit EPSILON initialization/assignment from constructors and assignment operator; src/pickDeliver/solution.cpp constructor initializer updated accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Enhancement, C/C++

Suggested reviewers

  • cvvergara
  • robe2

Poem

🐇 I tuck defaults into members snug and small,
Constructors breathe easy — no extra call.
A hop, a nibble, tidy lines in sight,
Variables cosy through day and night.
Hooray — small hops that make the code feel light! ✨

🚥 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 describes the main change: enabling the cppcoreguidelines-use-default-member-init clang-tidy check and fixing related violations.
Linked Issues check ✅ Passed All code changes directly address the objectives of issue #3041 by enabling the check in .clang-tidy and refactoring member initializations across multiple classes to use default initializers.
Out of Scope Changes check ✅ Passed All changes are in-scope: modifications to .clang-tidy configuration and refactoring of member initialization patterns across seven classes, all aligned with the cppcoreguidelines-use-default-member-init objective.

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

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.

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

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

🤖 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.

@Mohit242-bit
Copy link
Contributor Author

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

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