Procházet zdrojové kódy

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 před 3 roky
rodič
revize
3da54dcf9f
2 změnil soubory, kde provedl 26 přidání a 1 odebrání
  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.