View Issue Details

IDProjectCategoryView StatusLast Update
0035671FPCCompilerpublic2019-08-02 16:50
Reporterrd0xAssigned ToJonas Maebe 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.2.0Product Build 
Target VersionFixed in Version3.3.1 
Summary0035671: Enable range check for Delphi-mode
DescriptionFrom Anthony Walter on mailing list: https://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg51001.html

In Delphi Rio it triggers:
[dcc32 Error] Project1.dpr(16): E1012 Constant expression violates subrange bounds

So I think its a good idea to enable range checking by default for Delphi-mode for better compiler compatibility
Steps To Reproduceprogram Project1;

{$mode delphi}

type
  TSuit = (suHeart, suDiamond, suClub, suSpade);
  TRedSuit = suHeart..suDiamond;

var
  Suit: TRedSuit;
begin
  // This should generate an error, but {$mode delphi} allows it
  Suit := suClub;
end.
TagsNo tags attached.
Fixed in Revision42272
FPCOldBugId
FPCTarget-
Attached Files

Relationships

related to 0035753 resolvedJonas Maebe Delphi allows dereferencing a pointer to a [0..0] static array and accessing it with indices > 0, however 0035671 breaks this. 

Activities

Thaddy de Koning

2019-06-07 19:59

reporter   ~0116613

Well:

testme.pas(12,11) Warning: (4110) Range check error while evaluating constants (2 must be between 0 and 1)

So what exactly do you want?
You can always compile with -Sew (treat warnings as errors)

Marco van de Voort

2019-06-07 21:03

manager   ~0116616

(note that compiletime and runtime range checking are different things. Enabling normal runtime checking would only give you an error at runtime)

rd0x

2019-06-07 23:07

reporter   ~0116617

When compiling this example in Delphi it gives you a compile time error and stops. (as written above)
FPC compiles it and you can run it, in my eyes this is not Delphi compatible as it should act the same in {$mode delphi}. Thats what Delphi mode is for or?

Thaddy de Koning

2019-06-08 09:46

reporter   ~0116619

Last edited: 2019-06-08 09:48

View 2 revisions

FPC throws a warning. With -Sew it throws an error.

 fpc -Sew warnings.pas
Free Pascal Compiler version 3.3.1-r42152 [2019/06/01] for arm
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Linux for ARMHF
Compiling warnings.pas
warnings.pas(12,11) Warning: Range check error while evaluating constants (2 must be between 0 and 1)
warnings.pas(14) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcarm returned an error exitcode

I only changed the name of your program. Looks to me enough.

rd0x

2019-06-08 10:46

reporter   ~0116620

Delphi throws an error by default, so FPC should enable -Sew in {$mode Delphi} as default too

Marco van de Voort

2019-06-08 13:44

manager   ~0116625

Only recent delphis do, and we are not errormessage compatible to delphi.

And the -Sew is a complete nono, since that turns every warning into an error

Martok

2019-06-08 15:18

reporter   ~0116627

Runtime range checks ($R) must be default-disabled in Delphi mode, as Delphi (and TP) are formally defined in {$R-}.

Compile time rangechecks are different, and in this examle is (and always has been) an error:
[DCC Fehler] Project1.dpr(13): E1012 Konstantenausdruck verletzt untere Grenzen

Issue History

Date Modified Username Field Change
2019-06-03 23:10 rd0x New Issue
2019-06-07 19:59 Thaddy de Koning Note Added: 0116613
2019-06-07 21:03 Marco van de Voort Note Added: 0116616
2019-06-07 23:07 rd0x Note Added: 0116617
2019-06-08 09:46 Thaddy de Koning Note Added: 0116619
2019-06-08 09:48 Thaddy de Koning Note Edited: 0116619 View Revisions
2019-06-08 10:46 rd0x Note Added: 0116620
2019-06-08 13:44 Marco van de Voort Note Added: 0116625
2019-06-08 15:18 Martok Note Added: 0116627
2019-06-22 19:30 Jonas Maebe Assigned To => Jonas Maebe
2019-06-22 19:30 Jonas Maebe Status new => resolved
2019-06-22 19:30 Jonas Maebe Resolution open => fixed
2019-06-22 19:30 Jonas Maebe Fixed in Version => 3.3.1
2019-06-22 19:30 Jonas Maebe Fixed in Revision => 42272
2019-06-22 19:30 Jonas Maebe FPCTarget => -
2019-06-22 21:52 Jonas Maebe Relationship added related to 0035753
2019-08-02 16:50 rd0x Status resolved => closed