Why I am getting clang-3.3 compile error with boost 1.53?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 7.3
  • Red Hat Enterprise Linux 7.4

Issue

  • Compiling code like this fails with an error: no matching function for call to 'get' func(std::get<indices>(args)...): in RHEL7.4

    • Save the following code to test.cpp

      #include <boost/signals2/signal.hpp>
      int main()
      {
      boost::signals2::signal<void()> s;
      s();
      }
      
    • Compile with:

      # clang test.cpp --std=c++11 -lstdc+ -o test
      
    • It will throw several errors, starting with:

      In file included from test.cpp:1:
      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:89:16: error: no matching function for call to 'get'
        func(std::get<indices>(args)...);
             ^-----------
      

Resolution

  • This is a known issue which is being tracked in Red Hat bugzilla : 1444258.
  • Fixing this issue is not in scope for RHEL 7.4 and will be reviewed again in the RHEL7.5 timeframe. For more details, please contact Red Hat Technical support

Workaround

  • Configure the Boost.Config header to be smarter about detecting C++11 features when compiling with Clang and libstdc++. Modify the code as follows:


    #include <boost/config.hpp> #if defined(__clang__) && __cplusplus >= 201103L # undef BOOST_NO_CXX11_HDR_TUPLE #endif #include <boost/signals2/signal.hpp> int main() { boost::signals2::signal<void()> s; s(); }

Root Cause

  • Clang always identifies itself as GCC 4.2.1, which Boost 1.53 interprets to mean that no C++11 library features are supported. The <boost/config/stdlib/libstdcpp3.hpp> file has:

    //  C++0x headers in GCC 4.3.0 and later
    // 
    #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3) || !defined(__GXX_EXPERIMENTAL_CXX0X__)
    #  define BOOST_NO_CXX11_HDR_ARRAY 
    #  define BOOST_NO_CXX11_HDR_REGEX  
    #  define BOOST_NO_CXX11_HDR_TUPLE
    #  define BOOST_NO_CXX11_HDR_UNORDERED_MAP
    #  define BOOST_NO_CXX11_HDR_UNORDERED_SET
    #  define BOOST_NO_CXX11_HDR_FUNCTIONAL
    #endif
    
  • In fact, clang is using the RHEL libstdc++ headers from GCC 4.8, which do support the <tuple> header. This mis-detection will happen for any version of Clang, because they all identify as GCC 4.2.1 so get treated the same by the logic above.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments