Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using from_range with std::vector<>::const_iterator #2926

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

burlog
Copy link
Contributor

@burlog burlog commented Oct 29, 2024

This pull request addresses a compile error occurring when attempting to instantiate std::vector with a constant value type.

The issue arose in catch_generators_range.hpp, where ResultType was defined as a value_type of const_iterator within GeneratorWrapper<ResultType> which is usually const. This caused a conflict with std::vector, which requires its value_type to be non-const.

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.99%. Comparing base (9c5a4cf) to head (8c69645).
Report is 2 commits behind head on devel.

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #2926   +/-   ##
=======================================
  Coverage   90.99%   90.99%           
=======================================
  Files         198      198           
  Lines        8597     8597           
=======================================
  Hits         7822     7822           
  Misses        775      775           

@horenmar
Copy link
Member

Can you provide a reproducer?

@burlog
Copy link
Contributor Author

burlog commented Oct 30, 2024

Hm, I see that const_iterators of the standard containers does not have const qualified value_type, so I don't know if my patch is relevant. On the other hand, removing const from value type here probably does not break anything.

I encounter this when I used yaml-cpp for parsing test cases. Simplyfied example is:

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators_range.hpp>

#include <yaml-cpp/yaml.h>

auto yaml = YAML::LoadFile("test.yaml");

TEST_CASE("test case") {
    auto value = GENERATE(from_range(yaml));
}

@horenmar
Copy link
Member

Hmmmm, I am pretty sure that's yaml-cpp being wrong, I opened up an issue: jbeder/yaml-cpp#1326

I'll have to think about whether I want to merge a workaround for now or not.

@horenmar
Copy link
Member

horenmar commented Nov 6, 2024

Just an FYI, if yaml-cpp upstream doesn't react, I plan to merge this on Friday.

@horenmar horenmar merged commit 7bbd4b9 into catchorg:devel Nov 9, 2024
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants