Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.other/inline8.C

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