Bug 137

Summary: Make Ipv4Address (uint32_t) constructor explicit
Product: ns-3 Reporter: Gustavo J. A. M. Carneiro <gjcarneiro>
Component: networkAssignee: ns-bugs <ns-bugs>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: pre-release   
Hardware: All   
OS: All   

Description Gustavo J. A. M. Carneiro 2008-02-12 10:07:24 UTC
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 Mathieu Lacage 2008-02-15 12:18:14 UTC
changeset 854dbe96e04c