title: While mocking with googletest, how to specify the argument type of an internal::AnythingMatcher for overloaded methods?
body: <h2>initial question</h2>
  <p>While testing with googletest, I use a mocked class, which contains an overloaded method, where one of the arguments differs in type.</p>
  <p>This leads to an ambiguous function call when I do</p>
  <p><code>EXPECT_CALL(mockedClass,mockedMethod(_,_)).WillOnce(Return(true));</code></p>
  <p>I tried to combine the <code>internal::AnythingMatcher</code> underscore with a type specification by replacing the argument in question with <code>An&lt;type&gt;()</code>, <code>TypedEq&lt;type&gt;(_)</code>, or <code>Matcher&lt;type&gt;(_)</code> as well as writing something like:</p>
  <pre><code>Matcher&lt;type&gt; customAnythingMatcher = _;
  EXPECT_CALL(mockedClass,mockedMethod(_,customAnythingMatcher)).WillOnce(Return(true));
  </code></pre>
  <p>all to no avail.
  Any hints how to disambiguate that call?</p>
  <h2>update #1</h2>
  <p>As requested, I elaborate by providing a minimal working -- or in this case a non-working -- example what I am trying to achieve:</p>
  <h3>myInterfaceToMock.h</h3>
  <pre><code>#ifndef MYINTERFACETOMOCK_H
  #define MYINTERFACETOMOCK_H
  
  #include &lt;QVariant&gt;
  #include &lt;QtGlobal&gt;
  class MyInterfaceToMock {
    virtual bool myMethod(QVariant &amp;firstArgument,
                          const quint8 secondArgument) const = 0;
    virtual bool myMethod(QByteArray &amp;firstArgument,
                          const quint16 secondArgument) const = 0;
    virtual bool myOtherMethod(quint8 firstAndOnlyArgument) const = 0;
  };
  
  #endif  // MYINTERFACETOMOCK_H
  </code></pre>
  <h3>myMock.h</h3>
  <pre><code>#ifndef MYMOCK_H
  #define MYMOCK_H
  
  #include &lt;gmock/gmock.h&gt;
  
  #include &lt;QtCore/QObject&gt;
  
  #include &quot;myInterfaceToMock.h&quot;
  class MyMock : public MyInterfaceToMock {
   public:
    // virtual bool myMethod(QVariant &amp;firstArgument, const quint8 secondArgument)
    // const = 0;
    MOCK_METHOD(bool, myMethod, (QVariant &amp;, const quint8), (const, override));
    // virtual bool myMethod(QByteArray &amp;firstArgument, const quint16
    // secondArgument) const = 0;
    MOCK_METHOD(bool, myMethod, (QByteArray &amp;, const quint16), (const, override));
    // virtual bool myOtherMethod(quint8 firstAndOnlyArgument) const = 0;
    MOCK_METHOD(bool, myOtherMethod, (quint8), (const, override));
  };
  
  #endif  // MYMOCK_H
  </code></pre>
  <h3>main.cpp</h3>
  <pre><code>#include &lt;gmock/gmock-matchers.h&gt;
  #include &lt;gmock/gmock.h&gt;
  #include &lt;gtest/gtest.h&gt;
  
  #include &lt;QCoreApplication&gt;
  #include &lt;QTimer&gt;
  
  class Tester : public QObject {
    Q_OBJECT
   public:
    Tester(QObject *parent = nullptr) : QObject(parent) {}
  
   public slots:
    void run() {
      ::testing::InitGoogleTest();
      emit(result(RUN_ALL_TESTS()));
    }
  
   signals:
    void result(int res);
  };
  
  #include &quot;main.moc&quot;
  
  int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);
  
    ::testing::InitGoogleMock(&amp;argc, argv);
  
    Tester *tester = new Tester(&amp;app);
  
    QObject::connect(tester, &amp;Tester::result, &amp;app, &amp;QCoreApplication::exit);
  
    QTimer::singleShot(0, tester, SLOT(run()));
  
    return app.exec();
  }
  
  #include &quot;myMock.h&quot;
  TEST(myTest, testMockOverload) {
    using namespace testing;
    MyMock mock;
    // Reference method, which does work all the time
    EXPECT_CALL(mock, myOtherMethod(_)).WillRepeatedly(Return(false));
    // Using a defined value as argument
    QVariant myVariant;
    EXPECT_CALL(mock, myMethod(myVariant, 3)).WillOnce(Return(true));
    bool result = mock.myMethod(myVariant, 3);
    ASSERT_TRUE(result);
    // Anything matcher for the unambiguous argument
    EXPECT_CALL(mock, myMethod(myVariant, _)).WillOnce(Return(true));
    result = mock.myMethod(myVariant, 3);
    ASSERT_TRUE(result);
    // Trying to match any passed qvariant
    EXPECT_CALL(mock, myMethod(An&lt;QVariant&gt;(), _)).WillOnce(Return(true));
  }
  </code></pre>
  <p>The compiler error is issued for the last line:</p>
  <pre><code>..\googlemock_disambiguate\main.cpp(55): error C2664: 'testing::internal::MockSpec&lt;bool (QByteArray &amp;,quint16)&gt; MyMock::gmock_myMethod(const testing::internal::WithoutMatchers &amp;,const testing::internal::Function&lt;bool (QByteArray &amp;,quint16)&gt; *) const': cannot convert argument 1 from 'testing::Matcher&lt;QVariant&gt;' to 'const testing::Matcher&lt;QVariant &amp;&gt; &amp;'
  ..\googlemock_disambiguate\main.cpp(55): note: Reason: cannot convert from 'testing::Matcher&lt;QVariant&gt;' to 'const testing::Matcher&lt;QVariant &amp;&gt;'
  ..\googlemock_disambiguate\main.cpp(55): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
  </code></pre>
  <p>I have a guess that it might have sth. to do with the constness of the method, but I still do not understand the meaning of that error...</p>