eranpeer / FakeIt

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

Reset produces warning on gcc #178

Closed rbock closed 2 years ago

rbock commented 5 years ago

Hi,

Compiling this minimal program

#include <fakeit.hpp>

class Sample {
public:
  virtual ~Sample() = default;
};

int main()
{
    fakeit::Mock<Sample> mock;
    mock.Reset();
}

with gcc-8.4.8 or gcc-9.0.1 like this

g++ -Wall -Wextra -Werror -std=c++17 a.cpp

produces quite ugly warnings:

In file included from a.cpp:1:
fakeit.hpp: In instantiation of ‘static unsigned int fakeit::VTUtils::getOffset(R (C::*)(arglist ...)) [with C = fakeit::VTUtils::getVTSize() [with C = Sample]::Derrived; R = void; arglist = {}]’:
fakeit.hpp:5311:44:   required from ‘static unsigned int fakeit::VTUtils::getVTSize() [with C = Sample]’
fakeit.hpp:5977:54:   required from ‘void fakeit::DynamicProxy<C, baseclasses>::Reset() [with C = Sample; baseclasses = {}]’
fakeit.hpp:7929:13:   required from ‘void fakeit::MockImpl<C, baseclasses>::reset() [with C = Sample; baseclasses = {}]’
fakeit.hpp:8259:13:   required from ‘void fakeit::Mock<C, baseclasses>::Reset() [with C = Sample; baseclasses = {}]’
a.cpp:12:16:   required from here
fakeit.hpp:5273:28: error: cast between incompatible pointer to member types from ‘void (fakeit::VTUtils::getVTSize() [with C = Sample]::Derrived::*)()’ to ‘unsigned int (fakeit::VirtualOffsetSelector::*)(int)’ [-Werror=cast-function-type]
 5273 |             auto sMethod = reinterpret_cast<unsigned int (VirtualOffsetSelector::*)(int)>(vMethod);
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have not been able to figure out cause or remedy yet.

Best,

Roland

FranckRJ commented 2 years ago

Looks like it was fixed by #214 in 2.0.6.