Skip to content

fix: Wrong return type of copy_fn and missing typedef in destruct_range - #708

Merged
sdebionne merged 1 commit into
boostorg:developfrom
marco-langer:fix-algorithm
Sep 2, 2026
Merged

fix: Wrong return type of copy_fn and missing typedef in destruct_range#708
sdebionne merged 1 commit into
boostorg:developfrom
marco-langer:fix-algorithm

Conversation

@marco-langer

@marco-langermarco-langer commented Jul 5, 2022

Copy link
Copy Markdown
Contributor

Description

This PR fixes some minor issues in algorithm.hpp:

  • removed unnecessary non-const std::copy overload
  • fixed wrong return type of copy_fn
  • added missing typedef to destruct_range

Tasklist

  • Ensure all CI builds pass
  • Review and approve

@marco-langer
marco-langer marked this pull request as draft July 5, 2022 15:56
@codecov

codecovBot commented Jul 5, 2022

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.10%. Comparing base (573ba13) to head (7e87ecd).
⚠️ Report is 114 commits behind head on develop.

Additional details and impacted files
@@ Coverage Diff @@## develop #708 +/- ##
===========================================
- Coverage 81.10% 81.10% -0.01% 
===========================================
Files 117 117 Lines 5171 5170 -1 ===========================================
- Hits 4194 4193 -1 
Misses 977 977 
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mloskotmloskot added the cat/bug But reports and bug fixes label Jul 5, 2022
@mloskotmloskot added this to the Boost 1.80 milestone Jul 5, 2022

@mloskotmloskot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

Is this still a draft?

Comment threadinclude/boost/gil/algorithm.hpp
@marco-langer

marco-langer commented Jul 6, 2022

Copy link
Copy Markdown
ContributorAuthor

Is this still a draft?

I wanted to think a second time about these core library changes before rushing them as a last minute change into the next release.

  • Why didn't the missing typedef in destruct_range show up in the CI? Is this dead code? Should we add more test cases? Is this part, which deals with destructing non-trivial-destructible pixel types, some kind of academic over-engineering which has no real world application (otherwise there would have been already bug reports?)?
  • Are those two std::copy specializations really redundant? And if yes, is specialization of std::copy for pixel types necessary at all? Shouldn't std::copy internally already employ a memmove strategy in case of trivial copyable value types? Wouldn't this be a better solution rather than this near-UB reinterpret_cast of the pixel types? Are the pixel types trivial copyable? If not, why not?

@mloskot

Copy link
Copy Markdown
Member

I agree with your points @marco-langer
I also was wondering about the actual redundancy of the std::copy thing.
Let's postpone it after 1.80 is out - it's already too late for major changes (other than tweaking internal stuff like CI or CMake configs).

@mloskotmloskot modified the milestones: Boost 1.80, Boost 1.81+Jul 7, 2022
@mloskotmloskot modified the milestones: Boost 1.82, Boost 1.83+Mar 31, 2023
@mloskotmloskot modified the milestones: Boost 1.86, 1.87.0Aug 20, 2024
@sdebionne

Copy link
Copy Markdown
Contributor

I had this PR checked:

template <typename I, typename O> struct copy_fn {
BOOST_FORCEINLINE I operator()(I first, I last, O dst) const { return std::copy(first,last,dst); }
};

std::copy(first, last, dst) returns an output iterator of type O (one-past-the-last-written element in the destination), but the function's declared/returned type is I — the input iterator type. That's backwards: operator() should return O, not I.

Concretely this is used at algorithm.hpp:181cfor planar pixel copies:

static_for_each(first,last,dst,boost::gil::detail::copy_fn<IC1,IC2>());

where IC1 (source channel iterator) and IC2 (destination channel iterator) can be distinct types. Returning I instead of O either fails to compile when O isn't convertible to I, or silently returns the wrong iterator (converted back to the source type) when it happens to compile — losing the correct destination-advance information a caller would expect from a copy-like functor.

Dropping the redundant const-pointer std::copy overload nearby and fixes a missing value_t typedef in destruct_range_impl is correct.

@sdebionne
sdebionne marked this pull request as ready for review September 2, 2026 19:06
@sdebionne
sdebionne merged commit 60efbc2 into boostorg:developSep 2, 2026
2 checks passed
@sdebionnesdebionne modified the milestones: Boost 1.91, Boost 1.93Sep 2, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat/bugBut reports and bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@marco-langer@mloskot@sdebionne