title: Mock member function call to lambda
body: <p>Using c++17 and gmock, I am mocking a class and would like to redirect calls to one of its member functions to a lambda. Is this possible?</p>
  
  <p>He're a minimal example:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;gmock/gmock.h&gt;
  
  using ::testing::_;
  using ::testing::Invoke;
  using ::testing::Return;
  
  class Foo
  {
  public:
      virtual uint8_t MyCall(const uint8_t in) const
      {
          return in;
      }
  };
  
  class MockFoo : public Foo
  {
  public:
      MOCK_METHOD(uint8_t, MyCall, (const uint8_t), (const, override));
  };
  
  TEST(MyTest, MyTestCase)
  {
      MockFoo mock_foo;
      ON_CALL(mock_foo, MyCall(_)).WillByDefault(Invoke([](const uint8_t to) {
          static_cast&lt;void&gt;(to);
      }));
  }
  </code></pre>
  
  <p>I am getting the following error when compiling:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>demo.cpp: In member function 'virtual void MyTest_MyTestCase_Test::TestBody()':
  demo.cpp:82:7: error: no matching function for call to 'testing::internal::OnCallSpec&lt;unsigned char(unsigned char)&gt;::WillByDefault(std::decay&lt;MyTest_MyTestCase_Test::TestBody()::&lt;lambda(uint8_t)&gt; &gt;::type)'
       }));
         ^
  In file included from external/gtest/googlemock/include/gmock/gmock-function-mocker.h:42:0,
                   from external/gtest/googlemock/include/gmock/gmock.h:61,
                   from demo.cpp:2:
  external/gtest/googlemock/include/gmock/gmock-spec-builders.h:323:15: note: candidate: testing::internal::OnCallSpec&lt;F&gt;&amp; testing::internal::OnCallSpec&lt;F&gt;::WillByDefault(const testing::Action&lt;F&gt;&amp;) [with F = unsigned char(unsigned char)]
     OnCallSpec&amp; WillByDefault(const Action&lt;F&gt;&amp; action) {
                 ^~~~~~~~~~~~~
  external/gtest/googlemock/include/gmock/gmock-spec-builders.h:323:15: note:   no known conversion for argument 1 from 'std::decay&lt;MyTest_MyTestCase_Test::TestBody()::&lt;lambda(uint8_t)&gt; &gt;::type {aka MyTest_MyTestCase_Test::TestBody()::&lt;lambda(uint8_t)&gt;}' to 'const testing::Action&lt;unsigned char(unsigned char)&gt;&amp;
  </code></pre>