eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.23k stars 169 forks source link

Compilation Error when using Any-Matcher with Eigen::Vector2f argument #169

Closed mmatthe closed 2 years ago

mmatthe commented 5 years ago

Below code gets an error message when compiling with g++ 7.3.0:

#include "catch.hpp"
#include "fakeit.hpp"

#include "Eigen/Dense" // from http://eigen.tuxfamily.org/index.php?title=Main_Page
using Eigen::Vector2f;

struct S {
int a; 
int b;
};

class C3 {
public:
  virtual void f(Vector2f s1) = 0;
};

TEST_CASE("Fakeit cannot resolve overload with Vector2f when using any-matcher?") {
  using namespace fakeit;
  Mock<C3> mock;

  Verify(Method(mock, f)
     .Using(_)).Once();
}

The error message is:

/usr/bin/c++ -Wall -Wno-unknown-pragmas -std=c++1z -c -I -Ieigen -I -o test_fakeit.cpp.o /tests/test_fakeit.cpp
In file included from /tests/test_fakeit.cpp:2:0:
/tests/fakeit.hpp: In instantiation of ‘void fakeit::MethodMockingContext<R, arglist>::setMatchingCriteria(const matcherCreators& ...) [with matcherCreators = {fakeit::AnyMatcher}; <template-parameter-2-2> = void; R = void; arglist = {Eigen::Matrix<float, 2, 1, 0, 2, 1>}]’:
/tests/fakeit.hpp:7895:72:   required from ‘fakeit::MockingContext<void, arglist ...>& fakeit::MockingContext<void, arglist ...>::Using(const arg_matcher& ...) [with arg_matcher = {fakeit::AnyMatcher}; arglist = {Eigen::Matrix<float, 2, 1, 0, 2, 1>}]’
/tests/test_fakeit.cpp:71:3:   required from here
/tests/fakeit.hpp:7787:13: error: call of overloaded ‘CollectMatchers(const fakeit::AnyMatcher&)’ is ambiguous
             c.CollectMatchers(matcherCreator...);
             ^
/tests/fakeit.hpp:7529:16: note: candidate: typename std::enable_if<std::is_constructible<fakeit::MatchersCollector<index, arglist>::NakedArgType<index>, Head>::value, void>::type fakeit::MatchersCollector<index, arglist>::CollectMatchers(const Head&) [with Head = fakeit::AnyMatcher; unsigned int index = 0; arglist = {Eigen::Matrix<float, 2, 1, 0, 2, 1>}; typename std::enable_if<std::is_constructible<fakeit::MatchersCollector<index, arglist>::NakedArgType<index>, Head>::value, void>::type = void]
         ::type CollectMatchers(const Head &value) {
                ^~~~~~~~~~~~~~~
/tests/fakeit.hpp:7539:16: note: candidate: typename std::enable_if<std::is_constructible<fakeit::MatchersCollector<index, arglist>::NakedArgType<index>, Head>::value, void>::type fakeit::MatchersCollector<index, arglist>::CollectMatchers(const Head&, const Tail& ...) [with Head = fakeit::AnyMatcher; Tail = {}; unsigned int index = 0; arglist = {Eigen::Matrix<float, 2, 1, 0, 2, 1>}; typename std::enable_if<std::is_constructible<fakeit::MatchersCollector<index, arglist>::NakedArgType<index>, Head>::value, void>::type = void]
         ::type CollectMatchers(const Head &head, const Tail &... tail) {
                ^~~~~~~~~~~~~~~
/tests/fakeit.hpp:7566:16: note: candidate: typename std::enable_if<std::is_same<fakeit::AnyMatcher, Head>::value, void>::type fakeit::MatchersCollector<index, arglist>::CollectMatchers(const Head&) [with Head = fakeit::AnyMatcher; unsigned int index = 0; arglist = {Eigen::Matrix<float, 2, 1, 0, 2, 1>}; typename std::enable_if<std::is_same<fakeit::AnyMatcher, Head>::value, void>::type = void]
         ::type CollectMatchers(const Head &) {
                ^~~~~~~~~~~~~~~
/tests/fakeit.hpp:7574:16: note: candidate: typename std::enable_if<std::is_same<fakeit::AnyMatcher, Head>::value, void>::type fakeit::MatchersCollector<index, arglist>::CollectMatchers(const Head&, const Tail& ...) [with Head = fakeit::AnyMatcher; Tail = {}; unsigned int index = 0; arglist = {Eigen::Matrix<float, 2, 1, 0, 2, 1>}; typename std::enable_if<std::is_same<fakeit::AnyMatcher, Head>::value, void>::type = void]
         ::type CollectMatchers(const Head &head, const Tail &... tail) {
                ^~~~~~~~~~~~~~~

Compilation exited abnormally with code 1 at Tue Mar 12 07:46:25

The code compiles, when Vector2f is replaced by a simple struct S:

class C3 {
public:
  virtual void f(S s1) = 0;
};

Any hints on possible workarounds?

rpadrela commented 3 years ago

@mmatthe did you manage to fix the issue or find a workaround? I believe I've encounteredd the same (or similar) issue.

FranckRJ commented 2 years ago

Should be fixed by #276.