1// { dg-do run } 2// { dg-options "-O1" } 3// Origin: Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at> 4 5#include <map> 6#include <cstdlib> 7 8using namespace std; 9 10class NAMES_ITEM 11 { 12public: 13 char *name; 14 15 NAMES_ITEM(const NAMES_ITEM& item2); 16 17 NAMES_ITEM(const char* name2); 18 19 ~NAMES_ITEM(); 20 21 bool operator==(const NAMES_ITEM& n) const; 22 }; 23 24 25NAMES_ITEM::NAMES_ITEM (const NAMES_ITEM& item2) 26 { 27 size_t length=std::strlen(item2.name); 28 29 name=new char[length+1]; 30 std::memcpy(name,item2.name,length+1); 31 } 32 33NAMES_ITEM::NAMES_ITEM (const char* name2) 34 { 35 size_t length=std::strlen(name2); 36 37 name=new char[length+1]; 38 std::memcpy(name,name2,length+1); 39 } 40 41NAMES_ITEM::~NAMES_ITEM () 42{ 43 if (std::strcmp (name, "one") != 0) 44 abort (); 45 46 name=0; 47} 48 49bool NAMES_ITEM::operator==(const NAMES_ITEM& n) const 50{ 51 return (std::strcmp(name,n.name) == 0); 52} 53 54bool operator<(const NAMES_ITEM& n1, const NAMES_ITEM& n2) 55 { 56 return (std::strcmp(n1.name,n2.name) < 0); 57 } 58 59 typedef map<NAMES_ITEM,size_t,less<NAMES_ITEM> > lookup_t; 60 61 lookup_t lookup; 62 63 NAMES_ITEM item ("one"); 64main() 65 { 66 lookup.insert(pair<NAMES_ITEM,size_t>(item,0)); 67 } 68 69