Opened 8 years ago

Closed 6 years ago

#10328 closed Bugs (wontfix)

is_linked is broken for linear slist

Reported by: anonymous Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: intrusive
Version: Boost Development Trunk Severity: Problem
Keywords: Cc: antialize@…

Description

The following program should print "Ok" but it print "Arghhhh"

This is do to is_linked checking the next pointer which is nullptr for the last element. The example works fine when omitting the ,bi::linear<true> line

#include <boost/intrusive/slist.hpp>
#include <iostream>

namespace bi=boost::intrusive;
struct my_tag {};
typedef bi::slist_base_hook<bi::tag<my_tag>, bi::link_mode<bi::safe_link> > my_hook;

struct my_type: public my_hook {
  bool is_linked() const {
    return my_hook::is_linked();
  }
};

typedef bi::slist<my_type,
                  bi::base_hook<my_hook>
                  , bi::linear<true>
                  > my_list;

int main() {
  my_type item;
  my_list list;
  list.push_front(item);
  std::cout << (item.is_linked() ? "Ok": "Arghhhhh") << std::endl;
}

Change History (4)

comment:1 by antialize@…, 8 years ago

Cc: antialize@… added

comment:2 by Ion Gaztañaga, 8 years ago

As the null value is used to mark a node as "unlinked", it's not possible to know if an element is unlinked or it's the last element in null ended (linear) lists. Currently this problem has no solution. The only thing we can do without breaking some code is to document this behaviour.

comment:3 by anonymous, 8 years ago

I guess one could change one of the nulls, to be a self pointer (or more ugly a 1) pointer.

Ofcause if users read the actual pointer values that nothing can be changed. If that is not the case, then the unlinked status could be the element pointing to it self.

comment:4 by Ion Gaztañaga, 6 years ago

Resolution: wontfix
Status: newclosed

Reviewing old bugs. Due to ABI issues and the fact that a node pointing to null could be also not linked to anything, the estrange behaviour was documented in commit:

https://github.com/boostorg/intrusive/commit/5a7892a85913fa811800510b1f7de310c93f44f3

to warn users. Thanks for the report.

Note: See TracTickets for help on using tickets.