Skip to content

remove narrowing conversion in king_ordering.hpp#499

Merged
Becheler merged 3 commits into
boostorg:developfrom
Becheler:fix/king-ordering-size-t-narrowing
Jun 8, 2026
Merged

remove narrowing conversion in king_ordering.hpp#499
Becheler merged 3 commits into
boostorg:developfrom
Becheler:fix/king-ordering-size-t-narrowing

Conversation

@Becheler

@Becheler Becheler commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Refs #496

Before submitting

  • This PR targets the develop branch.
  • I searched for an existing PR or issue covering the same change.
  • My contribution is licensed under the Boost Software License 1.0.

Type of change

  • Bug fix
  • New feature or API addition
  • Refactor (no behavior change)
  • Documentation
  • Build, CI, or tooling
  • Other (specify below)

Does this PR introduce a breaking change?

  • Yes (describe migration impact below)
  • No

What this PR does

Two commits:

  1. Harden king_ordering.cpp unit test (it did not assert anything) to prevent regressions
  2. Convert king_ordering.hpp heap from int to std::ptrdiff_t so the size_t queue positions no longer narrow

Motivation

Refs #496

Testing

Same CI, more hardened tests, less warnings:

Job Baseline (develop) After fix Δ
MSVC 14.3 1226 1154 −72
ubuntu gcc-14 (14/17/20/23) 51 51 0
ubuntu clang-19 (14/17/20/23) 75 75 0
macOS clang 14 75 75 0
macOS clang 17 70 70 0
macOS clang 20 70 70 0
all cmake jobs 0 0 0

Checklist

  • Existing tests pass (b2 in the test/ directory).
  • New behavior is covered by a test, or this is a docs / build / refactor change.
  • Documentation was updated if user-facing behavior changed.
  • No new compiler warnings on the platforms I built against.

@Becheler Becheler added warning priority: high Blocks users or core functionality. Needs attention in the current cycle. labels Jun 6, 2026
@Becheler Becheler marked this pull request as ready for review June 7, 2026 11:58
@Becheler Becheler requested a review from jeremy-murphy as a code owner June 7, 2026 11:58
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Compiler-warning counts vs develop (auto-generated).
PR run 27091112381 vs develop run 27120109824 (2dd06ac7a7).

Job Baseline After Delta
macos (clang, 14) 75 75 0
macos (clang, 17) 70 70 0
macos (clang, 20) 70 70 0
ubuntu (clang-19, 14) 75 75 0
ubuntu (clang-19, 17) 75 75 0
ubuntu (clang-19, 20) 75 75 0
ubuntu (clang-19, 23) 75 75 0
ubuntu (gcc-14, 14) 51 51 0
ubuntu (gcc-14, 17) 51 51 0
ubuntu (gcc-14, 20) 51 51 0
ubuntu (gcc-14, 23) 51 51 0
windows_msvc_14_3 (msvc-14.3) 1226 1154 -72

@Becheler Becheler merged commit 0d3e577 into boostorg:develop Jun 8, 2026
50 checks passed

@jeremy-murphy jeremy-murphy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definite improvement to have proper unit tests, but a few comments and questions about code choices. :)

child_location = parent_location;
heap_child_location = heap_parent_location;
heap_parent_location = (int)(heap_child_location / 2);
heap_parent_location = (std::ptrdiff_t)(heap_child_location / 2);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast is redundant.

Suggested change
heap_parent_location = (std::ptrdiff_t)(heap_child_location / 2);
heap_parent_location = heap_child_location / 2;

Comment thread test/king_ordering.cpp
<< std::endl;
size_type bw = bandwidth(
G, make_iterator_property_map(&perm[0], index_map, perm[0]));
std::cout << " bandwidth: " << bw << std::endl;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just remove all the console output as it's just noise 99% of the time. If we need console output only occasionally, then it should use a logger with configurable output levels so that a developer can easily turn it on during development.

So wait... was this test not actually testing anything, just printing console output? 😅

Comment thread test/king_ordering.cpp
auto assert_valid_permutation
= [&index_map, n](const std::vector< Vertex >& order) {
BOOST_TEST(order.size() == n);
std::vector< bool > seen(n, false);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular use is OK, but in general prefer boost::dynamic_bitset.

Comment on lines +175 to +176
std::ptrdiff_t heap_parent_location
= (std::ptrdiff_t)(heap_child_location / 2);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast is redundant.

Suggested change
std::ptrdiff_t heap_parent_location
= (std::ptrdiff_t)(heap_child_location / 2);
std::ptrdiff_t heap_parent_location = heap_child_location / 2;

public:
bfs_king_visitor(OutputIterator* iter, Buffer* b, Compare compare,
PseudoDegreeMap deg, std::vector< int > loc, VecMap color,
PseudoDegreeMap deg, std::vector< std::ptrdiff_t > loc, VecMap color,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think this is std::ptrdiff_t?
I've looked at the code, and I'm having trouble figuring out what it should be, but I'm inclined to think it should be std::size_t, unless there is a requirement for it to be signed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: high Blocks users or core functionality. Needs attention in the current cycle. warning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants