2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.brendan / operators5.C
blobdedec90456803b842b44d6ed032cb5998faaff1c
1 // { dg-do run  }
2 // GROUPS passed operators
3 // Check that operators may be (directly) recursive.
5 extern "C" int printf (const char *, ...); 
7 struct base {
8         int i;
9 };
11 base base_variable;
13 base operator+ (const base& left, const base& right)
15         base ret_val;
17         ret_val.i = left.i + right.i;
18         return ret_val;
21 base operator- (const base& left, int right)
23         base ret_val;
25         ret_val.i = left.i - right;
26         return ret_val;
29 // Define the unary ! operator for class base to be the fibonachi
30 // operator.
32 base operator! (const base& right)
34         if (right.i < 2)
35                 return right;
36         else
37                 return ((!(right-1)) + (!(right-2)));
40 int main ()
42         base k;
44         k.i = 15;
45         k = !k;         // fib it!
47         if (k.i != 610)
48           { printf ("FAIL\n"); return 1; }
49         else
50           printf ("PASS\n");
52         return 0;