dascandy / hippomocks

GNU Lesser General Public License v2.1
196 stars 67 forks source link

Move semantics is not supported #116

Open MartinSager opened 1 year ago

MartinSager commented 1 year ago

Move semantics for function argument seems to to work. (g++ 11.4.00)

class INext {
public:
        virtual void doSomeThing(std::function<bool()>&& debounce) = 0;
};

TEST (moveAssignment)
{

    MockRepository mocks;
    INext *nextMock = mocks.Mock<INext>();
    mocks.ExpectCall(nextMock, INext::doSomeThing);
    nextMock->doSomeThing([]{return true;});
}

Results in

make -C HippoMocksTest/ runtest
make[1]: Entering directory '/home/sagerm2/dev/lib/hippomocks/HippoMocksTest'
g++  -I../HippoMocks/ -Wall -Wextra -pedantic -Wno-long-long -g -std=c++14 -c -o test_membermock.o test_membermock.cpp -MMD -MP
In file included from test_membermock.cpp:1:
../HippoMocks/hippomocks.h: In instantiation of ‘HippoMocks::TCall<Y, A>& HippoMocks::MockRepository::RegisterExpect_(Z2*, Y (Z::*)(A), HippoMocks::RegistrationType, const char*, const char*, long unsigned int) [with int X = 68; Z2 = INext; Y = void; Z = INext; A = std::function<bool()>&&]’:
test_membermock.cpp:68:11:   required from here
../HippoMocks/hippomocks.h:6051:49: warning: cast between incompatible pointer to member types from ‘void (HippoMocks::mockFuncs<INext, void>::*)(std::function<bool()>&&)’ to ‘void (HippoMocks::base_mock::*)()’ [-Wcast-function-type]
 6051 |                                                 reinterpret_cast<void (base_mock::*)()>(mfp),X);
      |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../HippoMocks/hippomocks.h: In instantiation of ‘void HippoMocks::mockFuncs<Z, void>::expectation1(A) [with int X = 68; A = std::function<bool()>&&; Z = INext]’:
../HippoMocks/hippomocks.h:6048:6:   required from ‘HippoMocks::TCall<Y, A>& HippoMocks::MockRepository::RegisterExpect_(Z2*, Y (Z::*)(A), HippoMocks::RegistrationType, const char*, const char*, long unsigned int) [with int X = 68; Z2 = INext; Y = void; Z = INext; A = std::function<bool()>&&]’
test_membermock.cpp:68:11:   required from here
../HippoMocks/hippomocks.h:4853:78: error: cannot bind rvalue reference of type ‘std::function<bool()>&&’ to lvalue of type ‘std::function<bool()>’
 4853 |                 myRepo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple<A>(a));
      |                                                                              ^~~~~~~~~~~~~~~
In file included from test_membermock.cpp:1:
../HippoMocks/hippomocks.h:621:21: note:   initializing argument 1 of ‘HippoMocks::ref_tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>::ref_tuple(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) [with A = std::function<bool()>&&; B = HippoMocks::NullType; C = HippoMocks::NullType; D = HippoMocks::NullType; E = HippoMocks::NullType; F = HippoMocks::NullType; G = HippoMocks::NullType; H = HippoMocks::NullType; I = HippoMocks::NullType; J = HippoMocks::NullType; K = HippoMocks::NullType; L = HippoMocks::NullType; M = HippoMocks::NullType; N = HippoMocks::NullType; O = HippoMocks::NullType; P = HippoMocks::NullType]’
  621 |         ref_tuple(A valueA = A(), B valueB = B(), C valueC = C(), D valueD = D(), E valueE = E(), F valueF = F(), G valueG = G(), H valueH = H(), I valueI = I(), J valueJ = J(), K valueK = K(), L valueL = L(), M valueM = M(), N valueN = N(), O valueO = O(), P valueP = P())
      |                   ~~^~~~~~~~~~~~
make[1]: *** [makefile:18: test_membermock.o] Error 1
make[1]: Leaving directory '/home/sagerm2/dev/lib/hippomocks/HippoMocksTest'
make: *** [Makefile:7: test] Error 2