Opened 13 years ago

Closed 13 years ago

Last modified 10 years ago

#3832 closed Bugs (fixed)

ptr_list const items

Reported by: matcatprg@… Owned by: Thorsten Ottosen
Milestone: Boost 1.43.0 Component: ptr_container
Version: Boost 1.50.0 Severity: Problem
Keywords: ptr_list const Cc:

Description

Similar to ticket #3249 (https://svn.boost.org/trac/boost/ticket/3249). ptr_list has problems with const items, but works fine with non-const items. Both push_back() and push_front() cause errors. I'm using gcc/g++ 4.4.1 on Ubuntu GNU/Linux.

Here is my compilation output (also included as an attachment for clarity):

In file included from /usr/include/boost/ptr_container/ptr_list.hpp:19,

from main.cpp:1:

/usr/include/boost/ptr_container/ptr_sequence_adapter.hpp: In member function ‘void boost::ptr_sequence_adapter<T, VoidPtrSeq, CloneAllocator>::push_back(typename boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<T, VoidPtrSeq>, CloneAllocator>::value_type) [with T = const BASE, VoidPtrSeq = std::list<void*, std::allocator<void*> >, CloneAllocator = boost::heap_clone_allocator]’: main.cpp:41: instantiated from here /usr/include/boost/ptr_container/ptr_sequence_adapter.hpp:249: error: invalid conversion from ‘const void*’ to ‘void*’ /usr/include/boost/ptr_container/ptr_sequence_adapter.hpp:249: error: initializing argument 1 of ‘void std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = void*, _Alloc = std::allocator<void*>]’

Again, the interesting line is: invalid conversion from ‘const void*’ to ‘void*’

The attached file source code, is the same as from the previous ticket.

Attachments (2)

main.cpp (877 bytes ) - added by matcatprg@… 13 years ago.
test source code
errors (914 bytes ) - added by matcatprg@… 13 years ago.
g++ errors

Download all attachments as: .zip

Change History (12)

by matcatprg@…, 13 years ago

Attachment: main.cpp added

test source code

by matcatprg@…, 13 years ago

Attachment: errors added

g++ errors

comment:1 by anonymous, 13 years ago

Found a workaround: use boost::shared_ptr with std::list.

comment:2 by anonymous, 13 years ago

If you use the trunk repository, it should work just fine IICR.

-Thorsten

comment:3 by matcatprg@…, 13 years ago

Resolution: fixed
Status: newclosed

The version from svn works fine.

Did you actually change something? Or was it that I didn't have the most recent version?

Matthew A. Todd

comment:4 by matcatprg@…, 13 years ago

For clarification:

I just tested release 1.42, and the same error occurs there as well. So its something that has changed since then.

Matthew A. Todd

comment:5 by anonymous, 13 years ago

Well, the problem is that I haven't comitted trunk to the release branch.

The change is not huge, but it might require a slight update to the docs too (not that the interfaces are affected).

The fix is basically just some meta-functions taking into account that T might be const, and if so, instantiate container<const void*> instead of container<void*>.

-Thorsten

comment:6 by anonymous, 11 years ago

Is there any chance you could do the same with ptr_unordered_map? Should I open a new bug?

in reply to:  6 comment:7 by matcatprg@…, 11 years ago

Replying to anonymous:

Is there any chance you could do the same with ptr_unordered_map? Should I open a new bug?

I'm a little busy with school at the moment, but I'd love to help. I'll go ahead and run the check once I get a chance (within next 3 or 4 weeks).

Matthew

in reply to:  6 comment:8 by matcatprg@…, 11 years ago

I tested ptr_unordered_map<const char, const BASE*>. The test program compiled and ran both with and with out the consts. It also worked when the mapped type wasn't a pointer (i.e: const BASE).

For completeness, I went ahead and retested ptr_list as well. The full results are as follows:

container type      | trunk (72523)   | 1_46_1
------------------- | --------------- | ----------------------------------------
ptr_list            | works           | fails as before (fix not pushed to releases yet)
ptr_unordered_map   | works           | works

The only problems I had were with grokking how to use the container (my inexperience + doc vagueness) and trying to get insert() to work. Regarding the docs, more elaboration would be nice (e.g: what can be a pointer: the mapped type).

Regarding insert(), I couldn't tell exactly what was wrong, but it didn't have anything to do with const. I ended up using the "[]" operator to do insertion (which isn't mentioned in the doc but works and appears to be part of the intended behaviour based on ptr_map_adapter.hpp)

Let me know if you want more information or help.

Matthew

comment:9 by matt, 10 years ago

Version: Boost 1.41.0Boost 1.50.0

Did this change ever land in the release branch? I'm still finding it with boost 1.50 installed with macports:

/opt/local/include/boost/ptr_container/ptr_sequence_adapter.hpp:249: error: invalid conversion from ‘const void*’ to ‘void*’

grep "BOOST_LIB_VERSION" /opt/local/include/boost/version.hpp => #define BOOST_LIB_VERSION "1_50"

g++ -v => gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

comment:10 by Marshall Clow, 10 years ago

This compiles correctly against the trunk, but fails against the release branch.

The error I get from clang is:

release/boost/ptr_container/ptr_sequence_adapter.hpp:249:37: error: 
      reference to type 'const value_type' (aka 'void *const') could not bind to
      an lvalue of type 'value_type' (aka 'const BASE *')
            this->base().push_back( x );  // strong, commit
                                    ^
Downloads/main.cpp:37:13: note: in instantiation of member function
      'boost::ptr_sequence_adapter<const BASE, std::list<void *,
      std::allocator<void *>>, boost::heap_clone_allocator>::push_back'
      requested here
    intList.push_back(a);
Note: See TracTickets for help on using tickets.