Răsfoiți Sursa

Symbolic constants: don't range check on use

If these constants are defined with an explicit type, they are already
truncated/checked at that point. If we range check them again on use, we
may get errors because at that point there is no explicit type cast
any more.
Jonas Maebe 3 ani în urmă
părinte
comite
3da54dcf9f
2 a modificat fișierele cu 26 adăugiri și 1 ștergeri
  1. 3 1
      compiler/ncon.pas
  2. 23 0
      tests/tbs/tb0693.pp

+ 3 - 1
compiler/ncon.pas

@@ -328,7 +328,9 @@ implementation
             begin
               if p.constdef=nil then
                 internalerror(200403232);
-              p1:=cordconstnode.create(p.value.valueord,p.constdef,true);
+              { no range checking; if it has a fixed type, the necessary value
+                truncation was already performed at the declaration time }
+              p1:=cordconstnode.create(p.value.valueord,p.constdef,false);
             end;
           conststring :
             begin

+ 23 - 0
tests/tbs/tb0693.pp

@@ -0,0 +1,23 @@
+{ %norun }
+
+
+{$r+}
+
+{$mode delphi}
+
+    type
+      TLanguages = (
+        lOne,
+        lTwo,
+        lThree,
+        lFour
+      );
+
+    const
+      LANGUAGE_NONE = TLanguages(255);
+    var
+      Lang: TLanguages;
+
+    begin
+     Lang := LANGUAGE_NONE;  //line 20
+    end.