View Issue Details

IDProjectCategoryView StatusLast Update
0036829FPCCompilerpublic2020-03-28 13:21
ReporteravkAssigned ToJonas Maebe 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionduplicate 
Platformx86, x86_64OSWindows, LinuxOS Version
Product Version3.3.1Product Build44264 
Target VersionFixed in Version 
Summary0036829: Compiler ignores the local {$OVERFLOWCHECKS} directive.
DescriptionIt looks like the FPC ignores the local {$OVERFLOWCHECKS} directive.

If you compile the attached example with the command (e. g.):
  fpc -O2 overflowcheck.pas

then it will print:

I = 0
J = 4294967295
K = -2147483648
L = 2147483647
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files
  • overflowcheck.pas (921 bytes)
    program overflowcheck;
    
    {$mode delphi}{$Q+}
    
    uses
      SysUtils;
    
    var
      I: DWord   = High(DWord);
      J: DWord   = 0;
      K: Integer = High(Integer);
      L: Integer = Low(Integer);
    
    begin
      try
        Inc(I);
        WriteLn('I = ', I);
      except
        on e: Exception do
          WriteLn(Format('%s with message "%s" during test Inc(I)', [e.ClassName, e.Message]));
      end;
      try
        Dec(J);
        WriteLn('J = ', J);
      except
        on e: Exception do
          WriteLn(Format('%s with message "%s" during test Dec(J)', [e.ClassName, e.Message]));
      end;
      try
        Inc(K);
        WriteLn('K = ', K);
      except
        on e: Exception do
          WriteLn(Format('%s with message "%s" during test Inc(K)', [e.ClassName, e.Message]));
      end;
      try
        Dec(L);
        WriteLn('L = ', L);
      except
        on e: Exception do
          WriteLn(Format('%s with message "%s" during test Dec(L)', [e.ClassName, e.Message]));
      end;
    end.
    
    
    overflowcheck.pas (921 bytes)
  • overflowcheck2.pas (393 bytes)
    program overflowcheck2;
    
    {$mode delphi}{$Q+}
    
    uses
      SysUtils;
    
    var
      I: Integer;
      a: array of Integer;
    
    begin
      SetLength(a, 5);
      for I := 0 to High(a) do
        a[I] := High(Integer);
      try
        I := a[2] + 1;
        WriteLn('I = ', I);
      except
        on e: Exception do
          WriteLn(Format('%s with message "%s" during addition)', [e.ClassName, e.Message]));
      end;
    end.
    
    
    overflowcheck2.pas (393 bytes)

Relationships

duplicate of 0025201 closedJonas Maebe instead overflowcheck is used rangecheck 

Activities

avk

2020-03-26 11:13

reporter  

overflowcheck.pas (921 bytes)
program overflowcheck;

{$mode delphi}{$Q+}

uses
  SysUtils;

var
  I: DWord   = High(DWord);
  J: DWord   = 0;
  K: Integer = High(Integer);
  L: Integer = Low(Integer);

begin
  try
    Inc(I);
    WriteLn('I = ', I);
  except
    on e: Exception do
      WriteLn(Format('%s with message "%s" during test Inc(I)', [e.ClassName, e.Message]));
  end;
  try
    Dec(J);
    WriteLn('J = ', J);
  except
    on e: Exception do
      WriteLn(Format('%s with message "%s" during test Dec(J)', [e.ClassName, e.Message]));
  end;
  try
    Inc(K);
    WriteLn('K = ', K);
  except
    on e: Exception do
      WriteLn(Format('%s with message "%s" during test Inc(K)', [e.ClassName, e.Message]));
  end;
  try
    Dec(L);
    WriteLn('L = ', L);
  except
    on e: Exception do
      WriteLn(Format('%s with message "%s" during test Dec(L)', [e.ClassName, e.Message]));
  end;
end.

overflowcheck.pas (921 bytes)

avk

2020-03-26 11:39

reporter   ~0121718

Added another example.

overflowcheck2.pas (393 bytes)
program overflowcheck2;

{$mode delphi}{$Q+}

uses
  SysUtils;

var
  I: Integer;
  a: array of Integer;

begin
  SetLength(a, 5);
  for I := 0 to High(a) do
    a[I] := High(Integer);
  try
    I := a[2] + 1;
    WriteLn('I = ', I);
  except
    on e: Exception do
      WriteLn(Format('%s with message "%s" during addition)', [e.ClassName, e.Message]));
  end;
end.

overflowcheck2.pas (393 bytes)

Issue History

Date Modified Username Field Change
2020-03-26 11:13 avk New Issue
2020-03-26 11:13 avk File Added: overflowcheck.pas
2020-03-26 11:39 avk File Added: overflowcheck2.pas
2020-03-26 11:39 avk Note Added: 0121718
2020-03-28 13:21 Jonas Maebe Assigned To => Jonas Maebe
2020-03-28 13:21 Jonas Maebe Status new => resolved
2020-03-28 13:21 Jonas Maebe Resolution open => duplicate
2020-03-28 13:21 Jonas Maebe FPCTarget => -
2020-03-28 13:21 Jonas Maebe Relationship added duplicate of 0025201