In my private tree I recently added an assert in CursorSlice::inset() to
debug a bug, and it triggered quite often. The reason was that operator==
was comparing the addresses of CursorSlice::inset():

class CursorSlice {
        InsetBase & inset() const { return *inset_; }
        InsetBase * inset_;
}

bool operator==(CursorSlice const & p, CursorSlice const & q)
{
        return &p.inset() == &q.inset()
               && p.idx() == q.idx()
               && p.pit() == q.pit()
               && p.pos() == q.pos();
}

The only way I can imagine that this works with inset_ == 0 is if the
compiler optimizes the address taking operator and the dereferencing
operator away and does this instead:

        return p.inset_ == q.inset_
...

Is this allowed by the standard? Even if it is, should we not better be
explicit and apply the attached patch?


Georg
Index: src/cursor_slice.C
===================================================================
--- src/cursor_slice.C	(Revision 15165)
+++ src/cursor_slice.C	(Arbeitskopie)
@@ -79,7 +79,7 @@ CursorSlice::col_type CursorSlice::col()
 
 bool operator==(CursorSlice const & p, CursorSlice const & q)
 {
-	return &p.inset() == &q.inset()
+	return p.inset_ == q.inset_
 	       && p.idx() == q.idx()
 	       && p.pit() == q.pit()
 	       && p.pos() == q.pos();
@@ -88,7 +88,7 @@ bool operator==(CursorSlice const & p, C
 
 bool operator!=(CursorSlice const & p, CursorSlice const & q)
 {
-	return &p.inset() != &q.inset()
+	return p.inset_ != q.inset_
 	       || p.idx() != q.idx()
 	       || p.pit() != q.pit()
 	       || p.pos() != q.pos();

Reply via email to