Boost logo

Boost Users :

Subject: Re: [Boost-users] Error:" Non-const function called for const object" on Sun CC while using boost::multi_index::multi_index_container
From: joaquin_at_[hidden]
Date: 2008-10-07 11:58:12


Alexander Vinokur escribió:
> Hi,
>
> CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25
>
> Boost 1.34
>
> [...]
> Error message:
> "/home/BOOST/boost_1_34_0/boost/detail/allocator_utilities.hpp", line
> 176: Error: Non-const function Foo::__SLIP.DELETER__H() called for const
> object.
>
> "/home/BOOST/boost_1_34_0/boost/multi_index/detail/index_base.hpp", line
> 105: Where: While instantiating
> "boost::detail::allocator::destroy<Foo>(const Foo*)".
>
> "/home/BOOST/boost_1_34_0/boost/multi_index/detail/index_base.hpp", line
> 105: Where: Instantiated from non-template code.
>
>
> Important. If destructor ~Foo() is not virtual then there are no errors.
>

Seems like a compiler bug. Can you please try the following legal code?

  struct foo
  {
    virtual ~foo(){}
  };

  int main()
  {
    const foo* p=new foo;
    delete p;
  }

If the program fails with an error similar to yours then we got a bug.
The C++ standard allows
to delete a const T *, though I know this has posed problems with old
compilers incorrectly
assuming that you can't due to the constness of the T object. If this is
also the case with
Sun C++ 5.9 (at least if virtual dtors are involved) you can probably
fix it by adding a
BOOST_WORKAROUND on boost::detail::allocator::destroy that simply omits
the const qualifier for this particular compiler. Does this work? If so,
would you mind filing
a ticket with a patch so that I can add it to the trunk code?

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net