OSDN Git Service

* g++.dg/init/new1.C, g++.dg/template/alignof1.C,
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / init / init-ref1.C
1 // Submitted by Erik Rozendaal <dlr@acm.org>
2 // Test case for GNATS bug 787.
3 // { dg-do run }
4
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 static int calls;
9
10 int &foo (int &arg)
11 {
12   calls++;
13   arg=0;
14   return arg;
15 }
16
17 int &identity (int &x)
18 {
19   return x;
20 }
21
22 int main()
23 {
24   int a;
25
26   calls = 0;
27   int &b = ++foo (a);
28   if (calls > 1)
29     abort ();
30   if (&a != &b)
31     abort ();
32   if (a != 1)
33     abort ();
34
35   calls = 0;
36   int &c = ++identity (++foo (a));
37   if (calls > 1)
38     abort ();
39   if (&a != &c)
40     abort ();
41   if (a != 2)
42     abort ();
43
44   exit (0);
45 }