View Issue Details

IDProjectCategoryView StatusLast Update
0035910FPCCompilerpublic2019-08-03 15:49
ReporterThaddy de KoningAssigned ToJonas Maebe 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformallOSallOS Versionall
Product Version3.3.1Product Build42526 
Target VersionFixed in Version3.3.1 
Summary0035910: PATCH make the case statement in ISO mode behave like extendedpascal mode ( no compile time, but run-time error )
DescriptionIn ISO mode there is a bug that throws a compile time error even if all case labels are satisfied.

This patch solves this issue in so far that it now follows the same code path as extended pascal.
It still issues a - factually incorrect - warning, but it behaves now like:

1. warning that not all case labels are setisfied
2. Issues a run-time error if the case entry is outside of the range
3. accepts missing labels within the valid range

It is in my opinion also more correct in light of ISO7185:1990 6.8.3.5 Case-statements

Solves problems with a lot of existing code.
Steps To Reproducee.g:
{$mode iso}
program isobug(infile,outfile);
type
  operator = 3..5;
var
  x:integer;
  o:operator = 5;
begin
  x:=1;
  case o of
    3 : x := x;
    4 : x := x;
    5 : x := x;
  end;
end.
Additional InformationPatch for the test cases will follow separately.
TagsNo tags attached.
Fixed in Revision42574
FPCOldBugId
FPCTarget-
Attached Files
  • isocase.patch (1,324 bytes)
    Index: compiler/nset.pas
    ===================================================================
    --- compiler/nset.pas	(revision 42529)
    +++ compiler/nset.pas	(working copy)
    @@ -1219,17 +1219,12 @@
                    (labelcoverage<typcount) then
                   begin
                     { labels for some values of the operand are missing, and no else block is present }
    -                if not(m_iso in current_settings.modeswitches) then
    -                  begin
    -                    cgmessage(cg_w_case_incomplete);
    -                    { in Extended Pascal, this is a dynamic violation error if it actually happens }
    -                    if (m_extpas in current_settings.modeswitches) then
    +                cgmessage(cg_w_case_incomplete);
    +                { in ISO and Extended Pascal, this is a dynamic violation error if it actually happens }
    +                    if (m_extpas in current_settings.modeswitches) or
    +                       (m_iso in current_settings.modeswitches) then
                           elseblock:=ccallnode.createintern('fpc_rangeerror',nil);
    -                  end
    -                else
    -                  { this is an error in ISO Pascal }
    -                  message(cg_e_case_incomplete);
    -              end
    +             end
               end
             else if labelcoverage=typcount then
               begin
    
    isocase.patch (1,324 bytes)

Relationships

has duplicate 0035905 resolvedJonas Maebe case statement in ISO mode is no longer standards compliant. 

Activities

Thaddy de Koning

2019-07-30 10:46

reporter  

isocase.patch (1,324 bytes)
Index: compiler/nset.pas
===================================================================
--- compiler/nset.pas	(revision 42529)
+++ compiler/nset.pas	(working copy)
@@ -1219,17 +1219,12 @@
                (labelcoverage<typcount) then
               begin
                 { labels for some values of the operand are missing, and no else block is present }
-                if not(m_iso in current_settings.modeswitches) then
-                  begin
-                    cgmessage(cg_w_case_incomplete);
-                    { in Extended Pascal, this is a dynamic violation error if it actually happens }
-                    if (m_extpas in current_settings.modeswitches) then
+                cgmessage(cg_w_case_incomplete);
+                { in ISO and Extended Pascal, this is a dynamic violation error if it actually happens }
+                    if (m_extpas in current_settings.modeswitches) or
+                       (m_iso in current_settings.modeswitches) then
                       elseblock:=ccallnode.createintern('fpc_rangeerror',nil);
-                  end
-                else
-                  { this is an error in ISO Pascal }
-                  message(cg_e_case_incomplete);
-              end
+             end
           end
         else if labelcoverage=typcount then
           begin
isocase.patch (1,324 bytes)

Thaddy de Koning

2019-07-30 11:03

reporter   ~0117503

Last edited: 2019-07-30 11:52

View 2 revisions

ad 2. Note, I mean it now issues a run-time error when a value is within the range, but has no label.
example:
{$mode iso}
program isobug(infile,outfile);
type
  operator = 3..5;
var
  x:integer;
  o:operator = 4;
begin
  x:=1;
  case o of
    3 : x := x;
    // 4 : x := x;
    5 : x := x;
  end;
end.

This now compiles, but throws a run-time error. In my opinion the patch now has 99% correct behavior in iso mode.
Still spurious warning in case all labels in the range are satisfied. (remove the comment for 4).

Thaddy de Koning

2019-07-30 18:36

reporter   ~0117512

I might add that I suspect that the extended Pascal standard deliberately rephrases the error part from iso 7185:1990 to be dynamic, in the sense that it is not a new feature but was open to interpretation.

Issue History

Date Modified Username Field Change
2019-07-30 10:46 Thaddy de Koning New Issue
2019-07-30 10:46 Thaddy de Koning File Added: isocase.patch
2019-07-30 11:03 Thaddy de Koning Note Added: 0117503
2019-07-30 11:52 Thaddy de Koning Note Edited: 0117503 View Revisions
2019-07-30 18:36 Thaddy de Koning Note Added: 0117512
2019-07-30 19:04 Jonas Maebe Relationship added has duplicate 0035905
2019-08-03 15:49 Jonas Maebe Assigned To => Jonas Maebe
2019-08-03 15:49 Jonas Maebe Status new => resolved
2019-08-03 15:49 Jonas Maebe Resolution open => fixed
2019-08-03 15:49 Jonas Maebe Fixed in Version => 3.3.1
2019-08-03 15:49 Jonas Maebe Fixed in Revision => 42574
2019-08-03 15:49 Jonas Maebe FPCTarget => -