gpt4 book ai didi

c++ - clang 不喜欢 boost::signals2?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:47:50 25 4
gpt4 key购买 nike

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

#include <boost/signals2.hpp>

int foo();

struct first_nonzero
{
using result_type = int;

template <typename It>
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<int (), first_nonzero>;
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<indices>(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<int>::m_invoke<int,
boost::function<int ()>, 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<int>::operator()<boost::function<int
()>, 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<result_type>()(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<int,
>::m_invoke<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int ()> >,
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<int,
>::operator()<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int ()> >,
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<boost::signals2::detail::variadic_slot_invoker<int, >,
std::_List_iterator<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int
()> >, boost::signals2::mutex> > >, boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int ()>
>, 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<boost::signals2::detail::slot_call_iterator_t<boost::signals2::detail::variadic_slot_invoker<int, >,
std::_List_iterator<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int
()> >, boost::signals2::mutex> > >, boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int ()>
>, 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()<boost::signals2::detail::slot_call_iterator_t<boost::signals2::detail::variadic_slot_invoker<int, >,
std::_List_iterator<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int
()> >, boost::signals2::mutex> > >, boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int ()>
>, 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<int>::operator()<first_nonzero,
boost::signals2::detail::slot_call_iterator_t<boost::signals2::detail::variadic_slot_invoker<int, >,
std::_List_iterator<boost::shared_ptr<boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int
()> >, boost::signals2::mutex> > >, boost::signals2::detail::connection_body<std::pair<boost::signals2::detail::slot_meta_group, boost::optional<int> >, boost::signals2::slot<int (), boost::function<int ()>
>, boost::signals2::mutex> > >' requested here
return detail::combiner_invoker<typename combiner_type::result_type>()
^
/usr/include/boost/signals2/detail/signal_template.hpp:695:16: note: in instantiation of member function 'boost::signals2::detail::signal_impl<int (), first_nonzero, int, std::less<int>, boost::function<int ()>,
boost::function<int (const boost::signals2::connection &)>, 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<int (), first_nonzero, int, std::less<int>, boost::function<int ()>, boost::function<int (const boost::signals2::connection &)>,
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 版本 3.2-7ubuntu1 (tags/RELEASE_32/final)(基于 LLVM 3.2)g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1; Boost 库 1.54。

由于项目限制,我无法使用不同的编译器。有没有一种方法可以让我坚持使用 clang 并仍然使用 boost::signals2 库?

最佳答案

我知道这是一个老问题,但关于该主题的一些注释可能对其他读者有用。

由于问题似乎与使用 std::get 访问 std::tuple 的元素有关,最简单的尝试是定义 BOOST_NO_CXX11_HDR_TUPLE(Boost Macro Reference)。

来自 boost/signals2/detail/variadic_slot_invoker.hpp:

#ifdef BOOST_NO_CXX11_HDR_TUPLE
#include <boost/tuple/tuple.hpp>
#define BOOST_SIGNALS2_TUPLE boost::tuple
#define BOOST_SIGNALS2_GET boost::get
#else
#include <tuple>
#define BOOST_SIGNALS2_TUPLE std::tuple
#define BOOST_SIGNALS2_GET std::get
#endif

这样 Boost 将使用 boost::tuple/boost::get 而不是 std::tuple/std: :得到。(但是 boost::tuple 目前不支持可变参数模板)。

当然这只是一种解决方法。您可以获得一些时间来升级 Clang(版本 3.3/3.4 工作正常)。

关于c++ - clang 不喜欢 boost::signals2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22208417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com