Ryuta Suzuki | 17 Jul 15:43
Picon

Compiling boost with -std=c++0x (and -stdlib=libc++)

Hi,

I have trouble compiling the following trivial boost program

#include <boost/thread/thread.hpp>

int main()
{
  return 0;
}

Actually, clang and libc++ work perfectly fine:

[ryuta <at> oroppas]$ clang++ -stdlib=libc++ ./boost_thread.cpp

However, once we deploy -std=c++0x flag,

[ryuta <at> oroppas]$ clang++ -std=c++0x -stdlib=libc++ ./boost_thread.cpp 
In file included from ./boost_thread.cpp:1:
In file included from /usr/include/boost/thread/thread.hpp:17:
/usr/include/boost/thread/pthread/thread_data.hpp:36:17: error: call to deleted constructor of 'boost::shared_ptr<boost::detail::tss_cleanup_function>'
                func(func_),value(value_)
                ^    ~~~~~
/usr/include/boost/smart_ptr/shared_ptr.hpp:164:25: note: function has been explicitly marked deleted here
template<class T> class shared_ptr
                        ^
In file included from ./boost_thread.cpp:1:
In file included from /usr/include/boost/thread/thread.hpp:22:
/usr/include/boost/thread/detail/thread.hpp:395:13: error: call to deleted constructor of 'detail::thread_data_ptr'
      (aka 'shared_ptr<boost::detail::thread_data_base>')
            thread_data(thread_data_)
            ^           ~~~~~~~~~~~~
/usr/include/boost/smart_ptr/shared_ptr.hpp:464:36: note: function has been explicitly marked deleted here
    template<class Y> friend class shared_ptr;
                                   ^
/usr/include/boost/smart_ptr/shared_ptr.hpp:301:9: error: functional-style cast from 'const boost::shared_ptr<boost::detail::thread_data_base>' to 'this_type'
      (aka 'shared_ptr<boost::detail::thread_data_base>') uses deleted function
        this_type(r).swap(*this);
        ^~~~~~~~~~~
/usr/include/boost/thread/detail/thread.hpp:181:24: note: in instantiation of member function 'boost::shared_ptr<boost::detail::thread_data_base>::operator='
      requested here
            thread_info=other.thread_info;
                       ^
/usr/include/boost/smart_ptr/shared_ptr.hpp:464:36: note: candidate constructor (the implicit copy constructor) has been explicitly deleted
    template<class Y> friend class shared_ptr;
                                   ^
/usr/include/boost/smart_ptr/shared_ptr.hpp:227:5: note: candidate constructor [with Y = boost::detail::thread_data_base]
    shared_ptr( shared_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
    ^
3 errors generated.

I'm not sure if this could be a boost / clang / libc++ bug.
Any comment will be greatly appreciated.

Thanks,

Ryuta
_______________________________________________
cfe-dev mailing list
cfe-dev@...
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Jonathan Sauer | 17 Jul 16:48
Picon
Picon

Re: Compiling boost with -std=c++0x (and -stdlib=libc++)

Hello,

> #include <boost/thread/thread.hpp>
> 
> int main()
> {
>   return 0;
> }
> 
> Actually, clang and libc++ work perfectly fine:
> 
> [ryuta <at> oroppas]$ clang++ -stdlib=libc++ ./boost_thread.cpp
> 
> However, once we deploy -std=c++0x flag,
> 
> [ryuta <at> oroppas]$ clang++ -std=c++0x -stdlib=libc++ ./boost_thread.cpp 
> In file included from ./boost_thread.cpp:1:
> In file included from /usr/include/boost/thread/thread.hpp:17:
> /usr/include/boost/thread/pthread/thread_data.hpp:36:17: error: call to deleted constructor of 'boost::shared_ptr<boost::detail::tss_cleanup_function>'
>                 func(func_),value(value_)
>                 ^    ~~~~~
> /usr/include/boost/smart_ptr/shared_ptr.hpp:164:25: note: function has been explicitly marked
deleted here
> template<class T> class shared_ptr

This has to do with FDIS 12.8p18 (implicitely generated copy constructors are marked as deleted if the class
provides a move constructor). After adding this constructor to boost::shared_ptr, the code compiles:

    shared_ptr( shared_ptr<T> const & r )
    : px( r.px ), pn( r.pn ) // never throws
    {
    }

Out-of-the-box, Boost 1.46.1's shared_ptr does not provide a copy constructor such as the one above; indeed,
on line 210 of boost/smart_ptr/shared_ptr.hpp, there is the comment stating:

    //  generated copy constructor, destructor are fine

Boost's shared_ptr only provides the following:

    template<class Y>
    shared_ptr( shared_ptr<Y> const & r )
    : px( r.px ), pn( r.pn ) // never throws
    {
    }

>From my reading of 12.8, this is not considered to be a copy constructor, as according to p2, only *non-template*
constructors can be copy constructors. So clang tries to generate an implicit one, but that one already has been
deleted by the move constructor shared_ptr provides.

This is not fixed in Boost's current trunk, so I guess you should file a bug with Boost.

Jonathan
Ryuta Suzuki | 18 Jul 07:19
Picon

Re: Compiling boost with -std=c++0x (and -stdlib=libc++)


Thanks for the fix and info. I'll file a bug report to the boost developers.

Ryuta

On Sun, Jul 17, 2011 at 11:48 PM, Jonathan Sauer <jonathan.sauer-Mmb7MZpHnFY@public.gmane.org> wrote:
Hello,

> #include <boost/thread/thread.hpp>
>
> int main()
> {
>   return 0;
> }
>
> Actually, clang and libc++ work perfectly fine:
>
> [ryuta <at> oroppas]$ clang++ -stdlib=libc++ ./boost_thread.cpp
>
> However, once we deploy -std=c++0x flag,
>
> [ryuta <at> oroppas]$ clang++ -std=c++0x -stdlib=libc++ ./boost_thread.cpp
> In file included from ./boost_thread.cpp:1:
> In file included from /usr/include/boost/thread/thread.hpp:17:
> /usr/include/boost/thread/pthread/thread_data.hpp:36:17: error: call to deleted constructor of 'boost::shared_ptr<boost::detail::tss_cleanup_function>'
>                 func(func_),value(value_)
>                 ^    ~~~~~
> /usr/include/boost/smart_ptr/shared_ptr.hpp:164:25: note: function has been explicitly marked deleted here
> template<class T> class shared_ptr

This has to do with FDIS 12.8p18 (implicitely generated copy constructors are marked as deleted if the class
provides a move constructor). After adding this constructor to boost::shared_ptr, the code compiles:

   shared_ptr( shared_ptr<T> const & r )
   : px( r.px ), pn( r.pn ) // never throws
   {
   }

Out-of-the-box, Boost 1.46.1's shared_ptr does not provide a copy constructor such as the one above; indeed,
on line 210 of boost/smart_ptr/shared_ptr.hpp, there is the comment stating:

   //  generated copy constructor, destructor are fine

Boost's shared_ptr only provides the following:

   template<class Y>
   shared_ptr( shared_ptr<Y> const & r )
   : px( r.px ), pn( r.pn ) // never throws
   {
   }

>From my reading of 12.8, this is not considered to be a copy constructor, as according to p2, only *non-template*
constructors can be copy constructors. So clang tries to generate an implicit one, but that one already has been
deleted by the move constructor shared_ptr provides.

This is not fixed in Boost's current trunk, so I guess you should file a bug with Boost.


Jonathan


_______________________________________________
cfe-dev mailing list
cfe-dev-Tmj1lob9twqVc3sceRu5cw@public.gmane.org
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
cfe-dev@...
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

Gmane