[PATCH] Remove undefined behavior from list::push_back/front, emplace_back/front.

Andreas Jacobs buglibcxx at lancom.de
Thu Mar 27 04:22:09 PDT 2014


  Well, ehm, let's start with the good news: this patch actually solves the example main.cpp that I added to the bug report on January 15th. And it seems to me to be a valid fix for the functions push_front(), push_back(), emplace_front(), and emplace_back().

  Here's the bad news: Unfortunately, this patch doesn't solve the actual problem that std::list has: The pointers in __list_node_base still have the type pointer to __list_node, although they can point to the anchor node which is not a __list_node. The same is true for the __ptr_ member variables in __list_iterator and __list_const_iterator. This leads to undefined behaviour whenever these pointers are dereferenced although they currently point to the anchor node, even if they are only dereferenced to access __prev_ or __next_.

  I've slightly changed my example file to use splice() instead of push_front(). And then the described problem reappears:
  {F50161}

  Please note that I've used a more recent compiler this time: g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1. Please note further, that the patch I have proposed on February 28th (in the bug entry, because I didn't know about phabricator) does fix the problem for main2.cpp, too.

http://llvm-reviews.chandlerc.com/D3197



More information about the cfe-commits mailing list