Bug 137 - Make Ipv4Address (uint32_t) constructor explicit
: Make Ipv4Address (uint32_t) constructor explicit
Status: RESOLVED FIXED
: ns-3
node module
: pre-release
: All All
: P3 normal
Assigned To:
:
:
:
:
  Show dependency treegraph
 
Reported: 2008-02-12 10:07 EDT by
Modified: 2008-02-15 12:18 EDT (History)


Attachments


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2008-02-12 10:07:24 EDT
I just lost a ton of time because of an accidental implicit conversion:

Ipv4EndPoint *
Ipv4EndPointDemux::Allocate (Ipv4Address address, Ipv4Address localInterface)
{
[...]
}

Ipv4EndPoint *
Ipv4EndPointDemux::Allocate (uint16_t port)
{
  return Allocate (Ipv4Address::GetAny (), port);
}

In this case, Allocate (Ipv4Address::GetAny (), port) ends up calling
Ipv4EndPointDemux::Allocate (Ipv4Address address, Ipv4Address localInterface),
because the 'uint16_t port' parameter was being implicitly converted to
Ipv4Address (!).  The solution is to add an 'explicit' keyword to the
constructor.  It doesn't even break any existing NS-3 code.

diff -r 084b07dceafb src/node/ipv4-address.h
--- a/src/node/ipv4-address.h    Mon Feb 11 14:46:44 2008 +0000
+++ b/src/node/ipv4-address.h    Tue Feb 12 15:06:34 2008 +0000
@@ -40,7 +40,7 @@ public:
    * input address is in host order.
    * \param address The host order 32-bit address
    */
-  Ipv4Address (uint32_t address);
+  explicit Ipv4Address (uint32_t address);
   /** 
     * \brief Constructs an Ipv4Address by parsing a the input C-string
     *
------- Comment #1 From 2008-02-15 12:18:14 EDT -------
changeset 854dbe96e04c