Bug 350 - Ptr<T> has operator < but no operator >, causes subtle bugs
Ptr<T> has operator < but no operator >, causes subtle bugs
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: core
ns-3.2
All All
: P2 minor
Assigned To: Mathieu Lacage
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-09-16 10:46 UTC by Gustavo J. A. M. Carneiro
Modified: 2008-10-16 06:17 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gustavo J. A. M. Carneiro 2008-09-16 10:46:31 UTC
I had a comparison operator involving smart pointer fields that looked like this:

bool PyViz::TransmissionSampleKey::operator < (PyViz::TransmissionSampleKey const &other) const
{
  if (this->transmitter < other.transmitter)
    {
      return true;
    }
  if (this->transmitter > other.transmitter)
    {
      return false;
    }
  if (this->receiver < other.receiver)
    {
      return true;
    }
  if (this->receiver > other.receiver)
    {
      return false;
    }
  if (this->channel < other.channel)
    {
      return true;
    }
  else
    {
      return false;
    }
}

I was using these PyViz::TransmissionSampleKey values as keys of a std::map, and the std::map was going berserk, with completely erroneous operation.

After many hours of debugging I tracked it down to the above comparison function.  It turns out that we have a custom Ptr<T> operator < function, but no operator >.  It seems that C++ is autogenerating some operator > function, but the autogenerated function and the manual function are not self-consistent.

To fix my problem I am changing the > comparisons to !=, but I think this might bite someone else in the future.  In principle, defining the remaining operators should be enough to solve the problems.
Comment 1 Mathieu Lacage 2008-10-16 06:17:17 UTC
changeset cb3da9028895