ChimeraTK / project-template

Template for new projects. Can also be used to update cmake scripts in existing projects by merging the changes. This repository intentionally does not have a README.md (which would create conflicts in the projects using this template). For documentation, please follow this link:
https://github.com/ChimeraTK/project-template/blob/master/HowTo_project-template.md
GNU Lesser General Public License v3.0
1 stars 3 forks source link

Enabling C++ 17 breaks Boost #3

Closed smarsching closed 1 year ago

smarsching commented 6 years ago

The cmake/enable_latest_cxx_support.cmake script breaks Boost because some parts of Boost still seem to use std::auto_ptr, but as of C++ 17 this class has been removed. It is possible that this still works with GCC / the GNU C library, but it does not work with Clang / libc++.

Below is an error message that I get when compiling the Control System Adapter, but I get a similar message when compiling the cppext library. There is a bug report for the Boost libarary, but it seems like the issue has not been resolved yet.

I suggest to avoid enabling the compiler's C++ 17 support. As far as I can tell, we are not using any features from C++ 17 anyway, so I do not see a benefit in compiling with C++ 17 features enabled, but maybe I a missing a point.

If we need C++ 17, we could think about using a workaround to reenable std::auto_ptr.

[  2%] Building CXX object CMakeFiles/ChimeraTK-ControlSystemAdapter.dir/src/ApplicationBase.cc.o
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/src/ApplicationBase.cc:8:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/ApplicationBase.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/DevicePVManager.h:11:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/shared_ptr.hpp:17:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:28:
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/detail/shared_count.hpp:348:33: error: 
      no template named 'auto_ptr' in namespace 'std'
    explicit shared_count( std::auto_ptr<Y> & r ): pi_( new sp_counted_i...
                           ~~~~~^
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/src/ApplicationBase.cc:8:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/ApplicationBase.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/DevicePVManager.h:11:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/shared_ptr.hpp:17:
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:256:65: error: 
      no member named 'auto_ptr' in namespace 'std'
template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr...
                                                           ~~~~~^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:256:75: error: 
      'T' does not refer to a value
  ...class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
                                                                     ^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:256:17: note: 
      declared here
template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr...
                ^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:256:81: error: 
      expected ';' at end of declaration
  ...class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
                                                                           ^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:256:82: error: 
      expected unqualified-id
  ...class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
                                                                            ^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:455:31: error: 
      no template named 'auto_ptr' in namespace 'std'
    explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
                         ~~~~~^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:468:22: error: 
      no template named 'auto_ptr' in namespace 'std'
    shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
                ~~~~~^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:545:34: error: 
      no template named 'auto_ptr' in namespace 'std'
    shared_ptr & operator=( std::auto_ptr<Y> & r )
                            ~~~~~^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:554:34: error: 
      no template named 'auto_ptr' in namespace 'std'
    shared_ptr & operator=( std::auto_ptr<Y> && r )
                            ~~~~~^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/shared_ptr.hpp:556:38: error: 
      no template named 'auto_ptr' in namespace 'std'
        this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
                                ~~~~~^
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/src/ApplicationBase.cc:8:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/ApplicationBase.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/DevicePVManager.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/PVManager.h:10:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/thread.hpp:13:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/thread/thread.hpp:12:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/thread/thread_only.hpp:22:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/thread/detail/thread.hpp:30:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/bind.hpp:22:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/bind/bind.hpp:26:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/mem_fn.hpp:22:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/bind/mem_fn.hpp:25:
/Users/termi/Applications/Homebrew/Installed/include/boost/get_pointer.hpp:48:23: error: 
      redefinition of 'get_pointer' as different kind of symbol
template<class T> T * get_pointer(std::auto_ptr<T> const& p)
                      ^
/Users/termi/Applications/Homebrew/Installed/include/boost/get_pointer.hpp:20:23: note: 
      previous definition is here
template<class T> T * get_pointer(T * p)
                      ^
/Users/termi/Applications/Homebrew/Installed/include/boost/get_pointer.hpp:48:40: error: 
      no member named 'auto_ptr' in namespace 'std'
template<class T> T * get_pointer(std::auto_ptr<T> const& p)
                                  ~~~~~^
/Users/termi/Applications/Homebrew/Installed/include/boost/get_pointer.hpp:48:49: error: 
      'T' does not refer to a value
template<class T> T * get_pointer(std::auto_ptr<T> const& p)
                                                ^
/Users/termi/Applications/Homebrew/Installed/include/boost/get_pointer.hpp:48:16: note: 
      declared here
template<class T> T * get_pointer(std::auto_ptr<T> const& p)
               ^
/Users/termi/Applications/Homebrew/Installed/include/boost/get_pointer.hpp:48:52: error: 
      expected expression
template<class T> T * get_pointer(std::auto_ptr<T> const& p)
                                                   ^
/Users/termi/Applications/Homebrew/Installed/include/boost/get_pointer.hpp:48:61: error: 
      expected ';' at end of declaration
template<class T> T * get_pointer(std::auto_ptr<T> const& p)
                                                            ^
/Users/termi/Applications/Homebrew/Installed/include/boost/get_pointer.hpp:49:1: error: 
      expected unqualified-id
{
^
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/src/ApplicationBase.cc:8:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/ApplicationBase.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/DevicePVManager.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/PVManager.h:10:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/thread.hpp:24:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/thread/future.hpp:25:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/thread/exceptional_ptr.hpp:10:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/exception_ptr.hpp:9:
/Users/termi/Applications/Homebrew/Installed/include/boost/exception/detail/exception_ptr.hpp:451:16: error: 
      no viable overloaded '='
  ...ret=exception_detail::exception_ptr_static_exception_object<exception_detail::bad_exception_>::e;
     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/termi/Applications/Homebrew/Installed/include/boost/exception/detail/exception_ptr.hpp:41:5: note: 
      candidate function (the implicit move assignment operator) not viable: 1st
      argument ('const boost::exception_ptr') would lose const qualifier
    exception_ptr
    ^
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/src/ApplicationBase.cc:8:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/ApplicationBase.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/DevicePVManager.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/PVManager.h:10:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/thread.hpp:24:
/Users/termi/Applications/Homebrew/Installed/include/boost/thread/future.hpp:433:49: error: 
      no matching member function for call to 'shared_from_this'
              detail::make_ready_at_thread_exit(shared_from_this());
                                                ^~~~~~~~~~~~~~~~
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/enable_shared_from_this.hpp:48:19: note: 
      candidate function not viable: no known conversion from
      'boost::detail::shared_state_base' to
      'boost::enable_shared_from_this<boost::detail::shared_state_base>' for
      object argument
    shared_ptr<T> shared_from_this()
                  ^
/Users/termi/Applications/Homebrew/Installed/include/boost/smart_ptr/enable_shared_from_this.hpp:55:25: note: 
      candidate function not viable: no known conversion from
      'boost::detail::shared_state_base' to 'const
      boost::enable_shared_from_this<boost::detail::shared_state_base>' for
      object argument
    shared_ptr<T const> shared_from_this() const
                        ^
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/src/ApplicationBase.cc:8:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/ApplicationBase.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/DevicePVManager.h:13:
In file included from /Users/termi/Documents/workspace/ChimeraTK-ControlSystemAdapter/include/ChimeraTK/ControlSystemAdapter/PVManager.h:10:
In file included from /Users/termi/Applications/Homebrew/Installed/include/boost/thread.hpp:24:
/Users/termi/Applications/Homebrew/Installed/include/boost/thread/future.hpp:753:17: error: 
      cannot initialize object parameter of type
      'boost::detail::shared_state_base' with an expression of type
      'boost::detail::shared_state<void>'
                mark_finished_internal(lock);
                ^~~~~~~~~~~~~~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
mhier commented 6 years ago

Even if we don't need C++ 17, we have to enable it. If we enabled only C++ 14, no application using ChimeraTK could be build with C++ 17. The compiler takes the lowest standard, if multiple flags are listed!

I am wondering a bit, we are testing against various boost versions on Linux and do not see this issue. Is this problem related do Mac only? In which context does it appear exactly? Did you modify something in the control system adapter?

mhier commented 6 years ago

A sorry, you mentioned clang. We test with gcc only. Maybe it is a clang issue?

smarsching commented 6 years ago

This is not so much a Clang issue as a libc++ issue. When enabling C++ 17, libc++ removes std::auto_ptr. Technically, this is correct as auto_ptr has been removed in C++ 17 (see here). So one could argue that glibc is wrong when it still provides auto_ptr when C++ 17 is enabled. Anyway, if you want to C++ 17 the best workaround is adding -D_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR to the compiler flags. This will tell libc++ that auto_ptr shall be provided, even though it is not part of the standard library any longer.

killenb commented 6 years ago

I just tried cppext with clang on Ubuntu 1604 (the oldest BOOST and clang we have) and on tumbleweed (newest). It compiles on both systems. Seems to be a MAC issue.

killenb commented 6 years ago

Hm, I somehow don't see the other comments, incl. smarsching proposing to add -D_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR on github.

@smarsching Could you please add this to the project template and try it out? I think it is a good solution until it is fixed in BOOST.

P.S. I don't know if my comment that it works with Ubuntu 1604 (oldest BOOST and clang) and tumbleweed (newest system we have) went online. It might be because g++ is the system compiler and libc++ ist compiled with it that there is no issue on Linux, while on MAC clang is the system compiler.

mhier commented 1 year ago

I think this is no longer relevant...