------- Comment #9 from rguenther at suse dot de  2009-09-09 11:30 -------
Subject: Re:  forward_list::sort violates strict aliasing
 rules

On Wed, 9 Sep 2009, paolo dot carlini at oracle dot com wrote:

> ------- Comment #8 from paolo dot carlini at oracle dot com  2009-09-09 11:23 
> -------
> if I understand correctly what we would change, I'm not sure to like this
> casting from _Fwd_list_node_base* to _Fwd_list_node* inside
> _Fwd_list_node_base...

No, it would be

Index: forward_list.h
===================================================================
--- forward_list.h      (revision 151557)
+++ forward_list.h      (working copy)
@@ -84,6 +84,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
   template<typename _Tp, typename _Alloc>
     struct _Fwd_list_node : public _Fwd_list_node_base<_Alloc>
     {
+      typedef _Fwd_list_node_base<_Alloc> _Base;
       typedef typename _Alloc::template rebind<_Fwd_list_node<_Tp, 
_Alloc> >
         ::other::pointer        _Pointer;

Index: forward_list.tcc
===================================================================
--- forward_list.tcc    (revision 151557)
+++ forward_list.tcc    (working copy)
@@ -87,7 +87,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       _M_sort_after(_Comp __comp)
       {
         // If `next' is 0, return immediately.
-        _Pointer __list = __static_pointer_cast<_Pointer>(this->_M_next);
+        _Pointer __list = 
__static_pointer_cast<_Pointer>(reinterpret_cast <_Base 
*>(this)->_M_next);
         if (!__list)
           return;

@@ -171,7 +171,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
             // Allow for nmerges == 0, the empty list case.
             if (__nmerges <= 1)
               {
-                this->_M_next = __list;
+                reinterpret_cast<_Base *>(this)->_M_next = __list;
                 return;
               }


but appearantly we are able to mess this up during folding again...

Richard.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41316

Reply via email to