首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gmock和boost::signals2的编译器错误

gmock和boost::signals2的编译器错误
EN

Stack Overflow用户
提问于 2020-12-15 04:06:20
回答 1查看 219关注 0票数 1

我已经解压了不再编译的代码。在boost 1.70和gmock 1.7.2中,代码编译时没有任何错误,但是在较新的库boost 1.72和gmock 1.10中,它不再编译。下面的错误非常隐秘。

非常感谢您的每一次帮助。

代码语言:javascript
复制
#include <boost/signals2.hpp>
#include <gtest/gtest.h>
#include <gmock/gmock.h>

using ::testing::Return;
using ::testing::_; // Matcher for parameters

class M{
public:
    MOCK_METHOD1(connect, boost::signals2::connection(boost::signals2::signal<void(int)>::slot_type slot));
};

TEST(A,B){
    M m;

    ON_CALL(m, connect(_)).WillByDefault(Return(boost::signals2::connection{}));
}

int main(){
    return 0;
}

以下是编译器的输出:

代码语言:javascript
复制
In file included from /home/xxx/mycode2/google-googletest/examples/test/main.cpp:1:
In file included from /home/xxx/my/boost_1_72_0/include/boost/signals2.hpp:19:
In file included from /home/xxx/my/boost_1_72_0/include/boost/signals2/signal.hpp:22:
In file included from /home/xxx/my/boost_1_72_0/include/boost/signals2/connection.hpp:24:
In file included from /home/xxx/my/boost_1_72_0/include/boost/signals2/slot.hpp:30:
In file included from /home/xxx/my/boost_1_72_0/include/boost/signals2/variadic_slot.hpp:24:
/home/xxx/my/boost_1_72_0/include/boost/signals2/detail/slot_template.hpp:160:26: error: call to implicitly-deleted copy constructor of 'std::tuple<boost::signals2::slot<void (int), boost::function<void (int)> > &&>'
        _slot_function = detail::get_invocable_slot(f, detail::tag_type(f));
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/xxx/my/boost_1_72_0/include/boost/signals2/detail/slot_template.hpp:85:9: note: in instantiation of function template specialization 'boost::signals2::slot<void (int), boost::function<void (int)> >::init_slot_function<std::tuple<boost::signals2::slot<void (int), boost::function<void (int)> > &&> >' requested here
        init_slot_function(f);
        ^
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:133:4: note: in instantiation of function template specialization 'boost::signals2::slot<void (int), boost::function<void (int)> >::slot<std::tuple<boost::signals2::slot<void (int), boost::function<void (int)> > &&> >' requested here
        : _M_head_impl(std::forward<_UHead>(__h)) { }
          ^
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/std_function.h:285:9: note: in instantiation of function template specialization 'testing::Action<boost::signals2::connection (boost::signals2::slot<void (int), boost::function<void (int)> >)>::ActionAdapter::operator()<boost::signals2::slot<void (int), boost::function<void (int)> > >' requested here
        return (*_Base::_M_get_pointer(__functor))(
               ^
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/std_function.h:676:33: note: in instantiation of member function 'std::_Function_handler<boost::signals2::connection (boost::signals2::slot<void (int), boost::function<void (int)> >), testing::Action<boost::signals2::connection (boost::signals2::slot<void (int), boost::function<void (int)> >)>::ActionAdapter>::_M_invoke' requested here
            _M_invoker = &_My_handler::_M_invoke;
                                       ^
/home/xxx/my/googletest/install-release-1.10.0-508-g5a509dbd/include/gmock/gmock-actions.h:477:9: note: in instantiation of function template specialization 'std::function<boost::signals2::connection (boost::signals2::slot<void (int), boost::function<void (int)> >)>::function<testing::Action<boost::signals2::connection (boost::signals2::slot<void (int), boost::function<void (int)> >)>::ActionAdapter, void, void>' requested here
      : fun_(ActionAdapter{::std::shared_ptr<ActionInterface<F>>(impl)}) {}
        ^
/home/xxx/my/googletest/install-release-1.10.0-508-g5a509dbd/include/gmock/gmock-actions.h:662:12: note: in instantiation of member function 'testing::Action<boost::signals2::connection (boost::signals2::slot<void (int), boost::function<void (int)> >)>::Action' requested here
    return Action<F>(new Impl<R, F>(value_));
           ^
/home/xxx/mycode2/google-googletest/examples/test/main.cpp:16:42: note: in instantiation of function template specialization 'testing::internal::ReturnAction<boost::signals2::connection>::operator Action<boost::signals2::connection (boost::signals2::slot<void (int), boost::function<void (int)> >)>' requested here
    ON_CALL(m, connect(_)).WillByDefault(Return(boost::signals2::connection{}));
                                         ^
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:640:17: note: explicitly defaulted function was implicitly deleted here
      constexpr tuple(const tuple&) = default;
                ^
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:523:19: note: copy constructor of 'tuple<boost::signals2::slot<void (int), boost::function<void (int)> > &&>' is implicitly deleted because base class '_Tuple_impl<0, boost::signals2::slot<void (int), boost::function<void (int)> > &&>' has a deleted copy constructor
    class tuple : public _Tuple_impl<0, _Elements...>
                  ^
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:351:17: note: explicitly defaulted function was implicitly deleted here
      constexpr _Tuple_impl(const _Tuple_impl&) = default;
                ^
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:327:7: note: copy constructor of '_Tuple_impl<0, boost::signals2::slot<void (int), boost::function<void (int)> > &&>' is implicitly deleted because base class '_Head_base<0UL, boost::signals2::slot<void (int), boost::function<void (int)> > &&>' has a deleted copy constructor
    : private _Head_base<_Idx, _Head>
      ^
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:128:17: note: explicitly defaulted function was implicitly deleted here
      constexpr _Head_base(const _Head_base&) = default;
                ^
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:165:13: note: copy constructor of '_Head_base<0, boost::signals2::slot<void (int), boost::function<void (int)> > &&, false>' is implicitly deleted because field '_M_head_impl' is of rvalue reference type 'boost::signals2::slot<void (int), boost::function<void (int)> > &&'
      _Head _M_head_impl;
            ^
/home/xxx/my/boost_1_72_0/include/boost/function/function_template.hpp:1119:21: note: passing argument to parameter 'f' here
  operator=(Functor f)
                    ^
1 error generated.
make[2]: *** [CMakeFiles/myapp.dir/build.make:63: CMakeFiles/myapp.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/myapp.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
EN

回答 1

Stack Overflow用户

发布于 2020-12-15 04:43:18

我能把这事办好

代码语言:javascript
复制
#include <boost/signals2.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>

using ::testing::_; // Matcher for parameters
using ::testing::Return;

struct M {
    MOCK_METHOD1(connect, boost::signals2::connection(boost::signals2::signal<void(int)>::slot_type slot));
};

TEST(A, B) {
    M m;
    ON_CALL(m, connect(_)).WillByDefault(Return(boost::signals2::connection{}));
}

通过使用此CMakeLists.txt:

代码语言:javascript
复制
project(stackoverflow)
cmake_minimum_required(VERSION 3.5)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

set(Boost_NO_SYSTEM_PATHS On)
set(BOOST_ROOT "/home/sehe/custom/boost_1_74_0")
find_package(Boost COMPONENTS system REQUIRED)

#include(GoogleTest)
enable_testing()
find_package(GMock REQUIRED)

include_directories(${Boost_INCLUDE_DIR})
ADD_EXECUTABLE(sotest test.cpp)

target_link_libraries(sotest ${BOOST_system_LIBRARY_RELEASE})
target_link_libraries(sotest gmock_main)
#gtest_add_tests(sotest "" AUTO)

,然后运行

代码语言:javascript
复制
cmake .
cmake --build .
./sotest

打印

PS:我从您的源程序中删除了int amin(){}以获得模拟main另外,我通过检查compile_command.json验证了包含路径是用于Boost 1.74.0的:

代码语言:javascript
复制
  "command": "/usr/bin/c++   -I/home/sehe/custom/boost_1_74_0 -I/usr/src/googletest/googlemock/include -I/usr/src/googletest/googletest/include    -o CMakeFiles/sotest.dir/test.cpp.o -c /home/sehe/Projects/mockingbird/test.cpp",
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65295718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档