Clang don't like boost :: signals2?

All day I kept getting compiler errors from parts of the code using the Boost :: Signals2 library. I have reduced what I'm trying to do with a minimal example:

#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(); } 

When I try to compile this snippet with

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

I get a template output error, which apparently comes from the signal library itself:

 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. 

After some time, I decided to give a crazy idea to try another compiler, and, to my surprise, if I compile the same fragment with

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

I have no mistakes. I am running Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2) and g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 ; Acceleration Libraries 1.54.

Due to project limitations, I cannot use another compiler. Is there a way I can stick with clang and still use boost :: signals2 library?

+6
source share
1 answer

I know this is an old question, but some comments on this topic may be useful to other readers.

Since the problem seems to be considering using std::get to access elements of a std::tuple , the simplest things are to try and determine BOOST_NO_CXX11_HDR_TUPLE ( Boost Macro Reference ).

From 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 

thus Boost will use boost::tuple / boost::get instead of std::tuple / std::get . (but boost::tuple does not currently have a variational pattern support).

Of course, this is just a workaround. You can get some time to upgrade Clang (version 3.3 / 3.4 works fine).

0
source

All Articles