summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.jason/init3.C
blob: 38e0e61d325a48a67241fae5547637c6b3555022 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// { dg-do run  }
// PRMS Id: 5652
// Bug: strings does not get initialized.

#include <string.h>

class My_string {
   char *str;
   int len;
public:
   My_string(const char* string);
   My_string(const My_string &);
   ~My_string() { delete str; }
   char* char_p() { return str; }
};

const My_string strings[4] = {
   "first string",
   "second string",
   "third string",
   "fourth string"
};

My_string::My_string(const char* string)
{
   len = strlen(string) + 1;
   str = new char[len];
   memcpy(str, string, len);
}

My_string::My_string(const My_string &string)
{
   len = string.len;
   str = new char[len];
   memcpy(str, string.str, len);
}

int main()
{
   My_string str1 = strings[0];
   return strcmp ("first string", str1.char_p ()) != 0;
}