The _Relative_pointer_impl (and its const variant) implementation invokes
undefined behavior as it computes differences and compares pointers pointing
to different objects.

For example

  int i;
  RelPtr<int> p, q;
  p.set(&i);
  q.set(&i);
  if (p == q)

will reconstruct pointer values based on the addresses of p and q.  This
invokes undefined behavior.

The fix is to do all the pointer arithmetic and the comparisons using
an unsigned integer type (uintptr_t), not using char *.

Likely this causes 23_containers/vector/ext_pointer/modifiers/insert.cc
to fail on alias-improvements branch for i?86 (points-to analysis will
correctly conclude that the objects pointed to by the pointers returned
from get() point to different objects).


-- 
           Summary: _Relative_pointer_impl invokes undefined behavior
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: critical
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


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

Reply via email to