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

VectorContains won't compile when combined using && #1092

Closed
rpavlik opened this issue Nov 10, 2017 · 4 comments
Closed

VectorContains won't compile when combined using && #1092

rpavlik opened this issue Nov 10, 2017 · 4 comments
Labels

Comments

@rpavlik
Copy link
Contributor

rpavlik commented Nov 10, 2017

Description

I tried to compose two VectorContains matchers with &&, but I get a compile error - using VS 2015 with the latest updates, currently using the most recent single header. Kinda looks like a template argument mis-deduction (I suspect the comparator type should be a vector of the value type, rather than just the value type - but I'm new to the insides of Catch), but I haven't tried it with GCC or Clang to get a clearer view of the message - I just found a different way to solve my problem for now.

Steps to reproduce

#include <cstdint>
#include <vector>

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"

TEST_CASE("Bug repro") {
    using Catch::Matchers::VectorContains;
    std::vector<std::uint16_t> myVec = { 1, 2, 3 };
    REQUIRE_THAT(myVec, VectorContains(std::uint16_t(1)) && VectorContains(std::uint16_t(2)));
}

(I actually found this with a user-defined type, but simplified it to uint16_t here for the sake of explanation - both show the bug, it's not specific to ints nor to my user types.)

In VS 2015, this will produce the error:

6>C:\Users\Ryan\src\subdiv2d\vendor\catch2\catch.hpp(2107): error C2679: binary '&&': no operator found which takes a right-hand operand of type 'const Catch::Matchers::Impl::MatcherBase<std::vector<uint16_t,std::allocator<_Ty>>,T>' (or there is no acceptable conversion)
6>          with
6>          [
6>              _Ty=uint16_t,
6>              T=uint16_t
6>          ]
6>  C:\Users\Ryan\src\subdiv2d\vendor\catch2\catch.hpp(2049): note: could be 'Catch::Matchers::Impl::MatchAllOf<ComparatorT> &Catch::Matchers::Impl::MatchAllOf<ComparatorT>::operator &&(const Catch::Matchers::Impl::MatcherBase<ArgT,ComparatorT> &)'
6>          with
6>          [
6>              ComparatorT=uint16_t,
6>              ArgT=uint16_t
6>          ]
6>  C:\Users\Ryan\src\subdiv2d\vendor\catch2\catch.hpp(2107): note: while trying to match the argument list '(Catch::Matchers::Impl::MatchAllOf<ComparatorT>, const Catch::Matchers::Impl::MatcherBase<std::vector<uint16_t,std::allocator<_Ty>>,T>)'
6>          with
6>          [
6>              ComparatorT=uint16_t
6>          ]
6>          and
6>          [
6>              _Ty=uint16_t,
6>              T=uint16_t
6>          ]
6>  C:\Users\Ryan\src\subdiv2d\vendor\catch2\catch.hpp(2106): note: while compiling class template member function 'Catch::Matchers::Impl::MatchAllOf<ComparatorT> Catch::Matchers::Impl::MatcherBase<std::vector<uint16_t,std::allocator<_Ty>>,ComparatorT>::operator &&(const Catch::Matchers::Impl::MatcherBase<std::vector<_Ty,std::allocator<_Ty>>,ComparatorT> &) const'
6>          with
6>          [
6>              ComparatorT=uint16_t,
6>              _Ty=uint16_t
6>          ]
6>  C:\Users\Ryan\src\subdiv2d\tests\BasicTests.cpp(116): note: see reference to function template instantiation 'Catch::Matchers::Impl::MatchAllOf<ComparatorT> Catch::Matchers::Impl::MatcherBase<std::vector<uint16_t,std::allocator<_Ty>>,ComparatorT>::operator &&(const Catch::Matchers::Impl::MatcherBase<std::vector<_Ty,std::allocator<_Ty>>,ComparatorT> &) const' being compiled
6>          with
6>          [
6>              ComparatorT=uint16_t,
6>              _Ty=uint16_t
6>          ]
6>  C:\Users\Ryan\src\subdiv2d\vendor\catch2\catch.hpp(2194): note: see reference to class template instantiation 'Catch::Matchers::Impl::MatcherBase<std::vector<uint16_t,std::allocator<_Ty>>,T>' being compiled
6>          with
6>          [
6>              _Ty=uint16_t,
6>              T=uint16_t
6>          ]
6>  C:\Users\Ryan\src\subdiv2d\tests\BasicTests.cpp(116): note: see reference to class template instantiation 'Catch::Matchers::Vector::ContainsElementMatcher<uint16_t>' being compiled

Extra information

  • Catch version: v2.0.1 (Generated: 2017-11-03 11:53:39.642003)
  • Operating System: Windows 10 1703
  • Compiler+version: Visual Studio 2015 Update 3
@horenmar
Copy link
Member

horenmar commented Nov 13, 2017

Spent some time looking through it, and as far as I can tell, the implementation of Matchers was kinda misguided in regards to its type usage. We made some internal changes that fix this issue going forward and should prevent it from repeating.

@philsquared
Copy link
Collaborator

Yeah, looks like that second template arg on MatcherBase was left over from some earlier refactoring attempt and shouldn't have been there. VectorContains seemed to be the only thing using it (incorrectly). I've removed it and your example should work now (I've added something similar to the self-test project). Thanks for reporting it, @rpavlik

@horenmar
Copy link
Member

Fixed in 3537b78

@philsquared philsquared added the Resolved - pending review Issue waiting for feedback from the original author label Nov 13, 2017
@horenmar
Copy link
Member

v2.1.0 is out with the fix.

@horenmar horenmar added Bug and removed Resolved - pending review Issue waiting for feedback from the original author labels Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants