1// { dg-do run } 2// GROUPS passed operators 3// Check that operators may be (directly) recursive. 4 5extern "C" int printf (const char *, ...); 6 7struct base { 8 int i; 9}; 10 11base base_variable; 12 13base operator+ (const base& left, const base& right) 14{ 15 base ret_val; 16 17 ret_val.i = left.i + right.i; 18 return ret_val; 19} 20 21base operator- (const base& left, int right) 22{ 23 base ret_val; 24 25 ret_val.i = left.i - right; 26 return ret_val; 27} 28 29// Define the unary ! operator for class base to be the fibonachi 30// operator. 31 32base operator! (const base& right) 33{ 34 if (right.i < 2) 35 return right; 36 else 37 return ((!(right-1)) + (!(right-2))); 38} 39 40int main () 41{ 42 base k; 43 44 k.i = 15; 45 k = !k; // fib it! 46 47 if (k.i != 610) 48 { printf ("FAIL\n"); return 1; } 49 else 50 printf ("PASS\n"); 51 52 return 0; 53} 54