{: test that -(-maxint-1) causes a fatal overflow error }

program d02b( output );

var
   i, k : integer;
   x    : real;

function side: integer;
begin
   side := k;
   k := k+1;
end;
begin {d02b}

   k := -1;
   i := -(side);
   if i <> 1 then
      writeln( 'unexpected value of -(-1) is ', i );

   if k <> 0 then
      writeln( 'side effect error evaluating abs' );

   x := -maxint; x := x - 1;
   x := -x; {OK}

   write( 'checking for -(-maxint-1) overflow, expect runtime error ... ' );
   k := -maxint; {OK}
   k := k-1; {!!! = -maxint - 1 ==> possible overflow}

   i := -k;    {!!! overflow}

   writeln;
   write( '-(-maxint-1) overflow not detected, result is ' );
   if i+1 = -maxint then writeln( '-maxint-1' )
   else writeln( i:1 );

end. { d02b }

