Skip to content

Compilation error when using MOCK_METHOD1 from GMock and nlohmann::json #1212

@urbanekpj

Description

@urbanekpj
  • What is the issue you have?
    Compilation error
  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
    code :
#include "stdafx.h"
#include <gmock/gmock.h>
#include <nlohmann/json.hpp>

using Json = nlohmann::json;
//using Json = std::wstring;
namespace tests {
/**/
class GMockTest {
public:
    GMockTest() = default;
    virtual ~GMockTest() = default;
    virtual void read(const Json& data){

    };
};

class GMockTestMock final : public GMockTest {
public:
    ~GMockTestMock() override{};

    MOCK_METHOD1(read, void(const Json&));
};

using ::testing::_;
using ::testing::AnyNumber;
using ::testing::Invoke;
TEST(RequestClient, read_test)
{
    auto io = std::make_shared<GMockTestMock>();
    EXPECT_CALL(*io, read(_)).WillRepeatedly(Invoke([&](const Json& data) {
    }));
}
}
  • What is the expected behavior?
    code compiled
  • And what is the actual behavior instead?
    compilation errors:

1> \x86-windows-static\include\gmock\gmock-actions.h(388): error C2666: 'testing::internal::linked_ptr<testing::ActionInterface>::operator ==': 3 overloads have similar conversions
1> with
1> [
1> F=void (const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &)
1> ]
1> \x86-windows-static\include\gtest\internal\gtest-linked_ptr.h(186): note: could be 'bool testing::internal::linked_ptr<testing::ActionInterface>::operator ==(T *) const'
1> with
1> [
1> F=void (const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &),
1> T=testing::ActionInterface<void (const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &)>
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\exception(321): note: or 'bool std::operator ==(const std::exception_ptr &,const std::exception_ptr &) noexcept' [found using argument-dependent lookup]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\exception(326): note: or 'bool std::operator ==(std::nullptr_t,const std::exception_ptr &) noexcept' [found using argument-dependent lookup]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\exception(331): note: or 'bool std::operator ==(const std::exception_ptr &,std::nullptr_t) noexcept' [found using argument-dependent lookup]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\system_error(266): note: or 'bool std::operator ==(const std::error_code &,const std::error_code &) noexcept' [found using argument-dependent lookup]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\system_error(272): note: or 'bool std::operator ==(const std::error_code &,const std::error_condition &) noexcept' [found using argument-dependent lookup]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\system_error(278): note: or 'bool std::operator ==(const std::error_condition &,const std::error_code &) noexcept' [found using argument-dependent lookup]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\system_error(284): note: or 'bool std::operator ==(const std::error_condition &,const std::error_condition &) noexcept' [found using argument-dependent lookup]
1> \x86-windows-static\include\nlohmann\json.hpp(16582): note: or 'bool nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer::operator ==(const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &,const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &) noexcept' [found using argument-dependent lookup]
1> \x86-windows-static\include\nlohmann\json.hpp(11112): note: or 'bool nlohmann::json_pointer<nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::operator ==(const nlohmann::json_pointer<nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> &,const nlohmann::json_pointer<nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> &) noexcept' [found using argument-dependent lookup]
1> \x86-windows-static\include\nlohmann\json.hpp(16653): note: or 'bool nlohmann::operator ==<nullptr,0>(const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &,const ScalarType) noexcept'
1> with
1> [
1> ScalarType=nullptr
1> ]
1> \x86-windows-static\include\gmock\gmock-actions.h(388): note: while trying to match the argument list '(const testing::internal::linked_ptr<testing::ActionInterface>, nullptr)'
1> with
1> [
1> F=void (const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &)
1> ]
1> \x86-windows-static\include\gmock\gmock-actions.h(386): note: while compiling class template member function 'bool testing::Action::IsDoDefault(void) const'
1> with
1> [
1> F=void (const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &)
1> ]
1> \x86-windows-static\include\gmock\gmock-spec-builders.h(1712): note: see reference to function template instantiation 'bool testing::Action::IsDoDefault(void) const' being compiled
1> with
1> [
1> F=void (const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &)
1> ]
1> \x86-windows-static\include\gmock\gmock-spec-builders.h(1232): note: see reference to class template instantiation 'testing::Action' being compiled
1> with
1> [
1> F=void (const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &)
1> ]
1> \tests\test_jsonrpczmq.cpp(31): note: see reference to class template instantiation 'testing::internal::TypedExpectation' being compiled
1> with
1> [
1> F=void (const nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &)
1> ]

Metadata

Metadata

Assignees

Labels

solution: proposed fixa fix for the issue has been proposed and waits for confirmation

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions