aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.mike/p646.C
blob: 2644c1b43dfdcc79033f2d593517aab0cfa3f5b3 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// GROUPS passed i960
/*
  Bug Id: bnr
  PMRS Id: p0000646
  Bug is: Urgent Code Generation Problem in gcc-i960 V 1.95
*/


// Special g++ Options: 

extern "C"
{
  void printf (char *, ...);
  void abort ();
}

struct foo
{
  static int si;
  int i;
  foo ();
  foo (const foo&);
  ~foo ();
};

int
foo_parm_returns_i (foo foo_arg)
{
  return foo_arg.i;
}

int foo::si = 0;

foo::foo ()
{
  si++;
  printf ("new foo @ 0x%x; now %d foos\n", this, si);
}

foo::foo (const foo &other)
{
  si++;
  printf ("another foo @ 0x%x; now %d foos\n", this, si);
  *this = other;
}

foo::~foo ()
{
  si--;
  printf ("deleted foo @ 0x%x; now %d foos\n", this, si);
}

int
return_1 ()
{
  foo f;
  printf ("returning 1\n");
  return 1;
}

int
return_arg (int arg)
{
  foo f;
  printf ("returning %d\n", arg);
  return arg;
}

int
return_sum (int x, int y)
{
  foo f;
  printf ("returning %d+%d\n", x, y);
  return x + y;
}

foo
return_foo ()
{
  foo f;
  printf ("returning foo\n");
  return f;
}

foo
return_named_foo () return f
{
  printf ("returning named foo\n");
  return f;
}

foo
foo_parm_returns_foo (foo f)
{
  return f;
}

void
abort_because (char *str)
{
  printf ("aborting because %s\n", str);
  abort ();
}

int
warn_return_1 ()
{
  foo f;
  printf ("returning 1\n");
}

int
warn_return_arg (int arg)
{
  foo f;
  printf ("returning %d\n", arg);
  arg;
}

int
warn_return_sum (int x, int y)
{
  foo f;
  printf ("returning %d+%d\n", x, y);
  x + y;
}

foo
warn_return_foo ()
{
  foo f;
  printf ("returning foo\n");
}

foo
nowarn_return_named_foo () return f
{
  printf ("returning named foo\n");
}

foo
warn_foo_parm_returns_foo (foo f)
{
  f;
}

main ()
{
  int ii = return_1 ();
  if (ii != 1)
    abort_because ("wrong value returned");
  int j = return_arg (42);
  if (j != 42)
    abort_because ("wrong value returned");
  int k = return_sum (-69, 69);
  if (k != 0)
    abort_because ("wrong value returned");
  foo f1 = return_named_foo ();
  if (foo::si != 1)
    abort_because ("wrong number of foos");
  f1.i = 5;
  int l = foo_parm_returns_i (f1);
  if (l != 5)
    abort_because ("l != 5");
  foo f2 = foo_parm_returns_foo (f1);
  if (foo::si != 2)
    abort_because ("wrong number of foos");
  if (f2.i != 5)
    abort_because ("f2.i != 5");
  foo f3 = return_foo ();
  if (foo::si != 3)
    abort_because ("wrong number of foos");
  printf("PASS\n");
  return 0;
}