Boost logo

Boost :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2006-11-13 05:05:58


On Nov 12, 2006, at 6:46 PM, David Abrahams wrote:

> Matthias Troyer <troyer_at_[hidden]> writes:
>
>> Hi Beman, hi all
>>
>> Due to recent changes to the filesystem library now, the header
>> detail/identifier.hpp is now included in my projects and contains the
>> dangerous code segment:
>
> Is it just dangerous by definition, because it breaks
> your code on your compiler, or is there something else about it that
> I'm missing?

Here is an example code exhibiting the bug. As far as I understand
section 14.8.2 of the standard, SFINAE does not apply here since
Id::value_type in detail/identifier.hpp is a valid type. To me this
does not seem to be a compiler bug, but I'm not an expert.

#include <boost/shared_ptr.hpp>
#include <boost/detail/identifier.hpp>

namespace my {
struct A {};

struct B
{
   B() {}
   virtual void foo()=0;
   virtual ~B() {}
};

void operator << (A&, boost::shared_ptr<B> const&) {}

}

int main()
{
   my::A a;
   boost::shared_ptr<my::B> b;
   a << b;
}

I provide an operator<< for the two types, but still Apple's version
of g++-4.0.1 tries to instantiate the general template in detail/
identifier.hpp, and aborts with the following error message:

src/boost/boost/detail/identifier.hpp: In instantiation of
'boost::identifier<my::B, boost::shared_ptr<my::B> >':
src/boost/boost/type_traits/is_base_and_derived.hpp:141:
instantiated from
'boost::detail::is_base_and_derived_impl2<boost::identifier<my::B,
boost::shared_ptr<my::B> >, boost::shared_ptr<my::B> >'
src/boost/boost/type_traits/is_base_and_derived.hpp:200:
instantiated from
'boost::detail::is_base_and_derived_impl<boost::identifier<my::B,
boost::shared_ptr<my::B> >, boost::shared_ptr<my::B> >'
src/boost/boost/type_traits/is_base_of.hpp:21: instantiated from
'boost::is_base_of<boost::identifier<my::B, boost::shared_ptr<my::B>
>, boost::shared_ptr<my::B> >'
src/boost/boost/utility/enable_if.hpp:36: instantiated from
'boost::enable_if<boost::is_base_of<boost::identifier<my::B,
boost::shared_ptr<my::B> >, boost::shared_ptr<my::B> >, my::A&>'
problem.cpp:22: instantiated from here
src/boost/boost/detail/identifier.hpp:61: error: cannot declare field
'boost::identifier<my::B, boost::shared_ptr<my::B> >::m_value' to be
of abstract type 'my::B'
problem.cpp:8: note: because the following virtual functions are
pure within 'my::B':
problem.cpp:10: note: virtual void my::B::foo()


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk