{: test that overflow on arithmetic addition causes a fatal error }

program d090( output );

var
   k : integer;

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

   k := 99;
   writeln( '99 + 1 is ', side + 1:1);
   if k <> 100 then
      writeln( 'add operator for debug has side effects' );

   k := -maxint;
   k := maxint + k;
   if k <> 0 then
      writeln( 'addition error line ', __LINE__:1 );

   k := -maxint + maxint;
   if k <> 0 then
      writeln( 'addition error line ', __LINE__:1 );

   k := maxint - 1;
   k := k + (-maxint);
   if k <> -1 then
      writeln( 'addition error line ', __LINE__:1 );

   k := -maxint + 1;
   k := k + maxint;
   if k <> 1 then
      writeln( 'addition error line ', __LINE__:1 );

   k := maxint div 2 + maxint div 2;
   if odd(maxint) and (k <> maxint-1) then
      writeln( 'addition error line ', __LINE__:1 );

   if not odd(maxint) and (k <> maxint)  then
      writeln( 'addition error line ', __LINE__:1 );

   k := maxint + (-1);
   if k+1 <> maxint then
      writeln( 'addition error line ', __LINE__:1 );

   k := -1 + maxint;
   if k+1 <> maxint then
      writeln( 'addition error line ', __LINE__:1 );

   k := -maxint div 2 + (-maxint div 2);
   if odd(maxint) and (k <> -maxint+1) then
      writeln( 'addition error line ', __LINE__:1 );

   if not odd(maxint) and (k <> -maxint)  then
      writeln( 'addition error line ', __LINE__:1 );

   k := -maxint + 1;
   if -k+1 <> maxint then
      writeln( 'addition error line ', __LINE__:1 );

   k := 1 + (-maxint);
   if k+maxint <> 1 then
      writeln( 'addition error line ', __LINE__:1 );

   k := maxint-1;
   if k+(-maxint) <> -1 then
      writeln( 'addition error line ', __LINE__:1 );

   k := maxint;
   writeln( 'maxint + 1 is ', k+1 );
   writeln( 'fails: overflow in add operator error is not detected' );
end. { d090 }

