Forum > FPC development

[SOLVED] FPC trunk: Existing code is broken about constant enumerations

(1/4) > >>

abouchez:
The new FPC trunk feature "Range checking for enumeration constants in Delphi mode" breaks existing code.
https://wiki.freepascal.org/User_Changes_Trunk#Range_checking_for_enumeration_constants_in_Delphi_mode

For instance, this code:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const  /// value stored into a TLanguages enumerate to mark no language selected yet  LANGUAGE_NONE = TLanguages(255);did work forever, and is broken by this new FPC trunk "feature".

The description in FPC user change list states that it is required in Delphi mode.
But this is untrue: above code compiles and work since Delphi 1 up to latest Delphi 11.1 with no troubles.
This is clearly a backward compatibility break, and avoid to run code working on Delphi and FPC since ever.
Where do I need to discuss and ask for removal of this "feature"?

I know forcing a value of an enumeration outside of its declared values is not beautiful, and should be avoided.
But it worked since forever, and compiles to fine code: 255 is just a byte, and the asm has no trouble with it.

See https://synopse.info/forum/viewtopic.php?id=6190

nanobit:
Many FPC users are not aware of a limitation (or bug) here.
What you see is supposed to prevent outer values and resultant undefined behavior in FPC apps (Delphi apps don't have this UB problem). See "enum cutoff implementation" in the notes

Thaddy:
It is a regression, and therefor a bug. 3.0.4 is fine, in trunk it is broken.

PascalDragon:
Please provide a full, self contained example that demonstrates the issue. The following code compiles in both FPC 3.2.2 and main and only triggers a warning:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program tenum; {$mode objfpc} type  TLanguages = (    lOne,    lTwo,    lThree,    lFour  ); const  LANGUAGE_NONE = TLanguages(255); begin end.

Bart:
This won't (fpc 3.2.2 on win32):

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TLanguages = (    lOne,    lTwo,    lThree,    lFour  ); const  LANGUAGE_NONE = TLanguages(255);var  Lang: TLanguages; begin Lang := LANGUAGE_NONE;  //line 20end.
--- Code: ---C:\Users\Bart\LazarusProjecten\ConsoleProjecten\test.pas
--- End code ---

Bart

Navigation

[0] Message Index

[#] Next page

Go to full version