Skip to content

Comments

clang-tidy: check and fix cppcoreguidelines-pro-type-member-init#3077

Open
ayushjariyal wants to merge 4 commits intopgRouting:developfrom
ayushjariyal:clang-tidy-pro-type-member-init
Open

clang-tidy: check and fix cppcoreguidelines-pro-type-member-init#3077
ayushjariyal wants to merge 4 commits intopgRouting:developfrom
ayushjariyal:clang-tidy-pro-type-member-init

Conversation

@ayushjariyal
Copy link

@ayushjariyal ayushjariyal commented Feb 23, 2026

Enable cppcoreguidelines-pro-type-member-init in .clang-tidy file and fix warning related to it.

Summary by CodeRabbit

  • Chores
    • Added default/value initializers across many modules to ensure members and local variables are initialized by default.
    • Reduced risk of uninitialized data, improving runtime stability and predictability.
    • Standardized initialization patterns project-wide to enhance robustness and maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e27848e and 5cea7ba.

📒 Files selected for processing (1)
  • include/vrp/tw_node.hpp

Walkthrough

Enabled clang-tidy's cppcoreguidelines-pro-type-member-init and applied value-initialization ({}) across many headers and sources to ensure deterministic default initialization of members and local variables.

Changes

Cohort / File(s) Summary
Clang-tidy Configuration
\.clang-tidy
Removed the disable for cppcoreguidelines-pro-type-member-init, enabling that check.
Core/common types
include/cpp_common/ch_edge.hpp, include/cpp_common/ch_vertex.hpp, include/cpp_common/line_vertex.hpp, include/cpp_common/path.hpp, include/cpp_common/base_graph.hpp
Added {} value-initializers to member declarations and local edge variables to guarantee zero-initialization.
Graph modules
include/chinese/chinesePostman.hpp, include/lineGraph/lineGraphFull.hpp
Changed local/member declarations to value-initialized forms (e.g., edge{}, m_num_edges{}).
Flow / MaxFlow
include/max_flow/maxflow.hpp, include/max_flow/minCostMaxFlow.hpp, src/max_flow/minCostMaxFlow.cpp
Value-initialized supersource/supersink members and local Flow_t variables to avoid indeterminate state.
Algorithm-specific headers
include/spanningTree/mst.hpp, include/trsp/edgeInfo.hpp, include/trsp/trspHandler.hpp, include/vrp/tw_node.hpp, include/yen/turnRestrictedPath.hpp
Added {} initializers to various protected/private members (ints, bools, structs) to ensure defined defaults.
Data fetchers / sources
src/cpp_common/pgdata_fetchers.cpp
Converted numerous local struct/variable declarations to value-initialized forms (e.g., Type var{}) for deterministic initialization.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Enhancement, C/C++

Suggested reviewers

  • cvvergara
  • robe2

Poem

🐰 Braces snug and tidy, fields wake clean and bright,
No more wild memory, everything’s initialized right.
Clang hops through the meadow, warnings trimmed away,
Leaves the code more peaceful — happy hop, hooray! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 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 change: enabling the cppcoreguidelines-pro-type-member-init clang-tidy check and fixing related warnings across the codebase.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
include/lineGraph/lineGraphFull.hpp (1)

59-62: 🧹 Nitpick | 🔵 Trivial

Redundant explicit initialization of m_num_edges(0).

Now that the default member initializer m_num_edges{} is in place (line 295), the m_num_edges(0) entry in the first constructor's initializer list (line 61) is redundant and can be removed.

♻️ Proposed fix
     explicit Pgr_lineGraphFull()
-        : Pgr_base_graph<G, T_V, T_E, t_directed>(),
-        m_num_edges(0) {
+        : Pgr_base_graph<G, T_V, T_E, t_directed>() {
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/lineGraph/lineGraphFull.hpp` around lines 59 - 62, The
Pgr_lineGraphFull() constructor redundantly initializes m_num_edges to 0 even
though m_num_edges has a default member initializer; remove m_num_edges(0) from
the constructor's initializer list in the explicit Pgr_lineGraphFull()
definition so the member default (m_num_edges{}) is used instead and leave the
base initializer Pgr_base_graph<G, T_V, T_E, t_directed>() intact.
include/chinese/chinesePostman.hpp (1)

79-81: ⚠️ Potential issue | 🟠 Major

Incomplete fix — private POD members still lack {} initializers.

superSource, superTarget, startPoint, and m_cost are plain scalar types without default member initializers or initializer-list entries, so the cppcoreguidelines-pro-type-member-init check still fires for them. Constructor-body assignment does not satisfy the check.

🛠️ Proposed fix
-    int64_t superSource, superTarget;
-    int64_t startPoint;
-    double m_cost;
+    int64_t superSource{}, superTarget{};
+    int64_t startPoint{};
+    double m_cost{};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/chinese/chinesePostman.hpp` around lines 79 - 81, Private POD members
superSource, superTarget, startPoint, and m_cost lack in-class default
initializers which triggers cppcoreguidelines-pro-type-member-init; add brace
initializers to their declarations (e.g., int64_t superSource{};, int64_t
superTarget{};, int64_t startPoint{};, double m_cost{};) or alternatively
initialize them in the member initializer list of the class constructors (not
via constructor-body assignments) to satisfy the guideline and silence the
check.
src/cpp_common/pgdata_fetchers.cpp (2)

354-354: 🧹 Nitpick | 🔵 Trivial

Inconsistent initialization style: = {} vs {}.

All other local variables in this file now use the direct brace-init form T var{}, but fetch_point still uses the legacy Point_on_edge_t point = {};. Both are semantically equivalent, but the inconsistency is worth tidying up.

♻️ Proposed fix
-    Point_on_edge_t point = {};
+    Point_on_edge_t point{};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cpp_common/pgdata_fetchers.cpp` at line 354, In fetch_point replace the
legacy initialization "Point_on_edge_t point = {};" with the consistent direct
brace-init form "Point_on_edge_t point{};" so it matches other locals in this
file; locate the declaration in the fetch_point function and update the
initialization style for the variable named point to use {} instead of = {}.

337-344: 🧹 Nitpick | 🔵 Trivial

Redundant NULL/0 assignments after {} initialization.

After Restriction_t restriction{}, the via pointer and via_size field are already zero-initialized, making restriction.via = NULL and restriction.via_size = 0 on lines 340-341 redundant before the getBigIntArr call reassigns them on line 342. These assignments are harmless but unnecessary.

♻️ Proposed cleanup
     Restriction_t restriction{};
     restriction.cost = getFloat8(tuple, tupdesc, info[0]);
-
-    restriction.via = NULL;
-    restriction.via_size = 0;
     restriction.via = getBigIntArr(tuple, tupdesc, info[1], &restriction.via_size);
     return restriction;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cpp_common/pgdata_fetchers.cpp` around lines 337 - 344, The local
Restriction_t restriction is value-initialized with Restriction_t restriction{},
so restriction.via and restriction.via_size are already zero-initialized; remove
the redundant assignments restriction.via = NULL and restriction.via_size = 0
before calling getBigIntArr. Keep the initialization of restriction and the
subsequent lines that set restriction.cost = getFloat8(...) and restriction.via
= getBigIntArr(...); this eliminates unnecessary assignments while preserving
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@include/chinese/chinesePostman.hpp`:
- Line 163: Nit: inconsistent initializer style — change the declaration using
CostFlow_t edge{} to match the existing style used elsewhere (CostFlow_t edge =
{}) so the file consistently uses the same aggregate initializer; locate the
declaration of CostFlow_t edge{} and replace its initializer to = {} to match
the instance at line 188 (symbol: CostFlow_t edge).

In `@include/vrp/tw_node.hpp`:
- Line 229: The doc comment for member m_type is incorrect (it currently reads
"The demand for the Node"); update the comment to describe the node's type
instead—e.g., change the trailing comment on NodeType m_type{}; to something
like "///< The type of the Node (NodeType) indicating its role/category" so it
accurately documents m_type and references the NodeType enum/class.

---

Outside diff comments:
In `@include/chinese/chinesePostman.hpp`:
- Around line 79-81: Private POD members superSource, superTarget, startPoint,
and m_cost lack in-class default initializers which triggers
cppcoreguidelines-pro-type-member-init; add brace initializers to their
declarations (e.g., int64_t superSource{};, int64_t superTarget{};, int64_t
startPoint{};, double m_cost{};) or alternatively initialize them in the member
initializer list of the class constructors (not via constructor-body
assignments) to satisfy the guideline and silence the check.

In `@include/lineGraph/lineGraphFull.hpp`:
- Around line 59-62: The Pgr_lineGraphFull() constructor redundantly initializes
m_num_edges to 0 even though m_num_edges has a default member initializer;
remove m_num_edges(0) from the constructor's initializer list in the explicit
Pgr_lineGraphFull() definition so the member default (m_num_edges{}) is used
instead and leave the base initializer Pgr_base_graph<G, T_V, T_E, t_directed>()
intact.

In `@src/cpp_common/pgdata_fetchers.cpp`:
- Line 354: In fetch_point replace the legacy initialization "Point_on_edge_t
point = {};" with the consistent direct brace-init form "Point_on_edge_t
point{};" so it matches other locals in this file; locate the declaration in the
fetch_point function and update the initialization style for the variable named
point to use {} instead of = {}.
- Around line 337-344: The local Restriction_t restriction is value-initialized
with Restriction_t restriction{}, so restriction.via and restriction.via_size
are already zero-initialized; remove the redundant assignments restriction.via =
NULL and restriction.via_size = 0 before calling getBigIntArr. Keep the
initialization of restriction and the subsequent lines that set restriction.cost
= getFloat8(...) and restriction.via = getBigIntArr(...); this eliminates
unnecessary assignments while preserving behavior.
ℹ️ Review info

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6ca7f3 and 8dff4a8.

📒 Files selected for processing (17)
  • .clang-tidy
  • include/chinese/chinesePostman.hpp
  • include/cpp_common/base_graph.hpp
  • include/cpp_common/ch_edge.hpp
  • include/cpp_common/ch_vertex.hpp
  • include/cpp_common/line_vertex.hpp
  • include/cpp_common/path.hpp
  • include/lineGraph/lineGraphFull.hpp
  • include/max_flow/maxflow.hpp
  • include/max_flow/minCostMaxFlow.hpp
  • include/spanningTree/mst.hpp
  • include/trsp/edgeInfo.hpp
  • include/trsp/trspHandler.hpp
  • include/vrp/tw_node.hpp
  • include/yen/turnRestrictedPath.hpp
  • src/cpp_common/pgdata_fetchers.cpp
  • src/max_flow/minCostMaxFlow.cpp
💤 Files with no reviewable changes (1)
  • .clang-tidy

@ayushjariyal
Copy link
Author

@cvvergara, Could you please review this PR?

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/chinese/chinesePostman.hpp (1)

79-81: ⚠️ Potential issue | 🟠 Major

Incomplete fix — scalar data members still lack value initializers.

The PR applies {} to local CostFlow_t edge variables but leaves four plain scalar members uninitialised at declaration:

int64_t superSource, superTarget;   // line 79 — uninitialized
int64_t startPoint;                 // line 80 — uninitialized
double  m_cost;                     // line 81 — uninitialized

These are precisely the cases cppcoreguidelines-pro-type-member-init targets. They are all assigned in the constructor body before being read, but they pass through an indeterminate state and—crucially—m_cost is exposed through the public DirectedChPP() accessor. None appear in the member-initialiser list (lines 113–117), so a thrown exception during early construction would leave them uninitialised for callers.

🛠️ Proposed fix
-    int64_t superSource, superTarget;
-    int64_t startPoint;
-    double m_cost;
+    int64_t superSource{};
+    int64_t superTarget{};
+    int64_t startPoint{};
+    double m_cost{-1};   // -1 is the sentinel already used in the constructor
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/chinese/chinesePostman.hpp` around lines 79 - 81, The scalar members
superSource, superTarget, startPoint and m_cost are left uninitialised at
declaration; add default member initializers (e.g. = 0 for the int64_t members
and = 0.0 for m_cost) or initialize them in the class constructor
member-initializer list for the class containing those fields (referencing the
members superSource, superTarget, startPoint, m_cost and the constructor that
currently omits them) so they cannot remain indeterminate if construction is
aborted early.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@include/vrp/tw_node.hpp`:
- Line 227: The Doxygen comment for member m_service_time is malformed (uses "//
/<") so its documentation is dropped; open the declaration of m_service_time in
tw_node.hpp and change the comment to a proper trailing Doxygen comment (use
"///<" like the other members on lines 224–229) so the service-time description
is picked up by the generated docs and stays consistent with the surrounding
members.

---

Outside diff comments:
In `@include/chinese/chinesePostman.hpp`:
- Around line 79-81: The scalar members superSource, superTarget, startPoint and
m_cost are left uninitialised at declaration; add default member initializers
(e.g. = 0 for the int64_t members and = 0.0 for m_cost) or initialize them in
the class constructor member-initializer list for the class containing those
fields (referencing the members superSource, superTarget, startPoint, m_cost and
the constructor that currently omits them) so they cannot remain indeterminate
if construction is aborted early.

ℹ️ Review info

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8dff4a8 and 49ea64a.

📒 Files selected for processing (2)
  • include/chinese/chinesePostman.hpp
  • include/vrp/tw_node.hpp

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.

♻️ Duplicate comments (1)
include/vrp/tw_node.hpp (1)

227-227: ⚠️ Potential issue | 🟡 Minor

Fix malformed Doxygen comment on m_service_time.

////< is not a valid trailing Doxygen comment, so the documentation won’t be picked up. Use ///< like the other members.

📝 Proposed fix
-     double m_service_time{};  ////< time it takes to be served
+     double m_service_time{};  ///< time it takes to be served
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/vrp/tw_node.hpp` at line 227, The member variable m_service_time has
a malformed Doxygen trailing comment using "////<"; change it to the correct
trailing-doc style "///<" so the comment is picked up like the other members
(locate the declaration of m_service_time and replace the "////< time it takes
to be served" with "///< time it takes to be served").
🤖 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/tw_node.hpp`:
- Line 227: The member variable m_service_time has a malformed Doxygen trailing
comment using "////<"; change it to the correct trailing-doc style "///<" so the
comment is picked up like the other members (locate the declaration of
m_service_time and replace the "////< time it takes to be served" with "///<
time it takes to be served").

ℹ️ Review info

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49ea64a and e27848e.

📒 Files selected for processing (1)
  • include/vrp/tw_node.hpp

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.

1 participant