The bug that I am reporting was confirmed on g++ versions 3.3.1, 3.2.3 and 2.95.3 on a Linux platform.
Although my simple sample program is quite self-explanatory, heres the problem in a nutshell: I am maintaining an STL map between IP addresses. In the sample code, I am maintaining a map between 105.52.20.33, 5000 and 47.32.68.95, 6000. When I display the entries in the map, the second IP address is overwritten by the first one. So instead of the mapping: 105.52.20.33, 5000 >>-->> 47.32.68.95, 6000 I get 105.52.20.33, 5000 >>-->> 105.52.20.33, 6000 The bug does not manifest when the code is compiled using native Solaris compiler version "WorkShop Compilers 5.0 02/04/10 C++ 5.0 Patch 107311-17" If you need any further clarification, kindly let me know. Regards, Kong Posh /////////////// Source Code Begin /////////////////////// #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <string> #include <map> #include <iostream> using namespace std; struct addrLessThan:public binary_function<const struct sockaddr_in, const struct sockaddr_in, bool> { bool operator()(const struct sockaddr_in addr1, const struct sockaddr_in addr2) const { bool retVal = true; string addrStr1 = inet_ntoa(addr1.sin_addr); string addrStr2 = inet_ntoa(addr2.sin_addr); if(addrStr1 > addrStr2) retVal = false; else if(addrStr1 == addrStr2) retVal = (addr1.sin_port < addr2.sin_port); return retVal; } }; typedef map<struct sockaddr_in, struct sockaddr_in, addrLessThan> IpV4AddrMap; main() { struct sockaddr_in actualAddress, mappedAddress; actualAddress.sin_port=5000; actualAddress.sin_addr.s_addr = inet_addr("105.52.20.33"); mappedAddress.sin_port=6000; mappedAddress.sin_addr.s_addr = inet_addr("47.32.68.95"); IpV4AddrMap map; map[actualAddress] = mappedAddress; IpV4AddrMap::iterator itor = map.find(actualAddress); if(itor != map.end()) { cout << "Key: " << inet_ntoa(itor->first.sin_addr) << ", " << itor->first.sin_port << endl << "Value: " << inet_ntoa(itor->second.sin_addr) << ", " << itor->second.sin_port << endl << endl; } return 0; } -- Summary: Non -native type entry is getting added to an STL Map incorrectly Product: gcc Version: 3.3.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kpbhat at sta dot samsung dot com CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22265