clang不喜欢boost :: signals2?

 维尼饭爱nichkhun_774 发布于 2023-01-19 18:32

我整天都在使用Boost :: Signals2库从代码部分中获取编译器错误.我已经将我想要做的事情简化为一个最小的例子:

#include 

int foo();

struct first_nonzero
{
    using result_type = int;

    template 
    result_type operator()(It first, It last) const
    {
    while(first != last)
    {
        if(*first != 0)
        {
            return *first;
        }
    }
    return 0;
    }
};

int foo()
{
    using signal = boost::signals2::signal;
    signal s;
    return s();
}

当我尝试编译此代码段时

clang -o foo.o -c foo.cpp -std=c++11 -Weverything -Wno-c++98-compat

我得到一个模板推导错误,似乎来自信号库本身:

In file included from foo.cpp:1:
In file included from /usr/include/boost/signals2.hpp:19:
In file included from /usr/include/boost/signals2/signal.hpp:38:
In file included from /usr/include/boost/signals2/variadic_signal.hpp:21:
/usr/include/boost/signals2/detail/variadic_slot_invoker.hpp:84:23: error: no matching function for call to 'get'
      return func(std::get(args)...);
                  ^~~~~~~~~~~~~~~~~
/usr/include/boost/signals2/detail/variadic_slot_invoker.hpp:78:18: note: in instantiation of function template specialization 'boost::signals2::detail::call_with_tuple_args::m_invoke, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type,
      boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>' requested here
      return m_invoke(resolver, func, indices_type(), args);
             ^
/usr/include/boost/signals2/detail/variadic_slot_invoker.hpp:120:18: note: in instantiation of function template specialization 'boost::signals2::detail::call_with_tuple_args::operator(), boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type,
      boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>' requested here
      return call_with_tuple_args()(connectionBody->slot.slot_function(), _args);
             ^
/usr/include/boost/signals2/detail/variadic_slot_invoker.hpp:106:18: note: in instantiation of function template specialization 'boost::signals2::detail::variadic_slot_invoker::m_invoke >, boost::signals2::slot >,
      boost::signals2::mutex> > >' requested here
      return m_invoke(connectionBody,
             ^
/usr/include/boost/signals2/detail/slot_call_iterator.hpp:82:35: note: in instantiation of function template specialization 'boost::signals2::detail::variadic_slot_invoker::operator() >, boost::signals2::slot >,
      boost::signals2::mutex> > >' requested here
          cache->result.reset(cache->f(*iter));
                              ^
/usr/include/boost/iterator/iterator_facade.hpp:514:20: note: in instantiation of member function 'boost::signals2::detail::slot_call_iterator_t,
      std::_List_iterator >, boost::signals2::slot >, boost::signals2::mutex> > >, boost::signals2::detail::connection_body >, boost::signals2::slot
      >, boost::signals2::mutex> >::dereference' requested here
      return f.dereference();
               ^
/usr/include/boost/iterator/iterator_facade.hpp:639:18: note: (skipping 1 context in backtrace; use -ftemplate-backtrace-limit=0 to see all)
      return iterator_core_access::dereference(this->derived());
             ^
foo.cpp:14:16: note: in instantiation of member function 'boost::iterator_facade,
      std::_List_iterator >, boost::signals2::slot >, boost::signals2::mutex> > >, boost::signals2::detail::connection_body >, boost::signals2::slot
      >, boost::signals2::mutex> >, int, boost::single_pass_traversal_tag, const int &, long>::operator*' requested here
        if(*first != 0)
           ^
/usr/include/boost/signals2/detail/result_type_wrapper.hpp:53:18: note: in instantiation of function template specialization
      'first_nonzero::operator(),
      std::_List_iterator >, boost::signals2::slot >, boost::signals2::mutex> > >, boost::signals2::detail::connection_body >, boost::signals2::slot
      >, boost::signals2::mutex> > >' requested here
      return combiner(first, last);
             ^
/usr/include/boost/signals2/detail/signal_template.hpp:241:18: note: in instantiation of function template specialization 'boost::signals2::detail::combiner_invoker::operator(),
      std::_List_iterator >, boost::signals2::slot >, boost::signals2::mutex> > >, boost::signals2::detail::connection_body >, boost::signals2::slot
      >, boost::signals2::mutex> > >' requested here
      return detail::combiner_invoker()
             ^
/usr/include/boost/signals2/detail/signal_template.hpp:695:16: note: in instantiation of member function 'boost::signals2::detail::signal_impl, boost::function,
      boost::function, boost::signals2::mutex>::operator()' requested here
    return (*_pimpl)(BOOST_SIGNALS2_SIGNATURE_ARG_NAMES(BOOST_SIGNALS2_NUM_ARGS));
           ^
foo.cpp:27:13: note: in instantiation of member function 'boost::signals2::signal, boost::function, boost::function,
      boost::signals2::mutex>::operator()' requested here
    return s();
        ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/utility:141:5: note: candidate template ignored: failed template argument deduction
    get(std::pair<_Tp1, _Tp2>& __in) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/utility:146:5: note: candidate template ignored: failed template argument deduction
    get(std::pair<_Tp1, _Tp2>&& __in) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/utility:151:5: note: candidate template ignored: failed template argument deduction
    get(const std::pair<_Tp1, _Tp2>& __in) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/array:267:5: note: candidate template ignored: failed template argument deduction
    get(array<_Tp, _Nm>& __arr) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/array:276:5: note: candidate template ignored: failed template argument deduction
    get(array<_Tp, _Nm>&& __arr) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/array:284:5: note: candidate template ignored: failed template argument deduction
    get(const array<_Tp, _Nm>& __arr) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/tuple:756:5: note: candidate template ignored: failed template argument deduction
    get(tuple<_Elements...>& __t) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/tuple:763:5: note: candidate template ignored: failed template argument deduction
    get(const tuple<_Elements...>& __t) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/tuple:770:5: note: candidate template ignored: failed template argument deduction
    get(tuple<_Elements...>&& __t) noexcept
    ^
1 error generated.

过了一段时间后,我决定尝试使用不同的编译器疯狂的想法,令我惊讶的是,如果我编译相同的代码片段

g++ -o foo.o -c foo.cpp -std=c++11 -Wall -Wextra -pedantic

我没有错.我正在Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1; 提升图书馆1.54.

由于项目限制,我不可能使用不同的编译器.有没有办法坚持clang并仍然使用boost :: signals2库?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有