Error:" Non-const function called for const object" on Sun CC while using boost::multi_index::multi_index_container
Hi, CC: Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25 Boost 1.34 Here are fragments of code that produces error "Non-const function called for const object". // -------------------- struct Foo { int m_int1; int m_int2; int get1 () const; int get2 () const;; ~Foo(); }; int Foo::get1 () const; { return m_int1; } int Foo::get2 () const; { return m_int2; } Foo::~Foo() { } // -------------------- typedef boost::multi_index::composite_key < Foo, BOOST_MULTI_INDEX_CONST_MEM_FUN( Foo, int, get1), BOOST_MULTI_INDEX_CONST_MEM_FUN( Foo, int, get2)
FooKey;
// -------------------- typedef boost::multi_index::multi_index_container < Foo, boost::multi_index::indexed_by < boost::multi_index::hashed_unique < FooKey > >
FooContainer;
// ================== // This function produces compilation error void bar () { FooContainer fooContainer; } 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. Alex Vinokur This message and the information contained herein is proprietary and confidential and subject to the Amdocs policy statement, you may review at http://www.amdocs.com/email_disclaimer.asp
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
participants (2)
-
Alexander Vinokur
-
joaquin@tid.es