Difference between revisions of "User Changes Trunk"

From Free Pascal wiki
Jump to navigationJump to search
(Documented variant manager change)
(31 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
== About this page==
 
== About this page==
  
Listed below are intentional changes made to the FPC compiler (trunk) since the [[User_Changes_3.0|previous release]] that may break existing code. The list includes reasons why these changes have been implemented, and suggestions for how you might adapt your code if you find that previously working code has been adversely affected by these recent changes.  
+
Listed below are intentional changes made to the FPC compiler (trunk) since the [[User_Changes_3.2|next upcoming release]] that may break existing code. The list includes reasons why these changes have been implemented, and suggestions for how you might adapt your code if you find that previously working code has been adversely affected by these recent changes.  
  
 
The list of new features that do not break existing code can be found [[FPC_New_Features_Trunk|here]].
 
The list of new features that do not break existing code can be found [[FPC_New_Features_Trunk|here]].
Line 8: Line 8:
  
 
== All systems ==
 
== All systems ==
 
=== Implementation Changes ===
 
 
==== Dynamic array parameters are passed like pointers ====
 
* '''Old behaviour''': When using the default calling convention, dynamic array parameters were passed on the stack.
 
* '''New behaviour''': When using the default calling convention, dynamic array parameters are now passed like a pointer (which may be in a register).
 
* '''Reason''': Delphi compatibility, ensuring that SetPointerProp can be used with dynamic arrays.
 
* '''Remedy''': Adjust pure assembler routines that have dynamic array parameters.
 
* '''svn''': 30870, 30878, 31622
 
 
==== VMT Interface table uses private variable FPC_EMPTYINTF ====
 
* '''Old behaviour''': The vIntfTable field has three possible values:
 
**Nil if the class doesn't implement any interface (but an ancestor might)
 
**A pointer to an interface table (with count <> 0) if the class implements any interface
 
**A pointer to FPC_EMPTYINTF if neither the class itself nor any ancestor implements an interface
 
* '''New behaviour''': The vIntfTable field has two possible values:
 
**Nil if neither the class nor any ancestor implements an interface
 
**A pointer to an interface table in any other case
 
* '''Reason''': FPC_EMPTYINTF had to be removed due to dynamic packages support on PE-based systems
 
* '''Remedy''': Adjust code accordingly
 
* '''svn''': 34087
 
 
==== Modeswitch ''TypeHelpers'' in Delphi modes enables ''type helper''-syntax ====
 
* '''Old behaviour''': The modeswitch ''TypeHelpers'' is enabled by default in Delphi modes and allows to extend primitive types with ''record helper'' types.
 
* '''New behaviour''':
 
**The modeswitch is no longer set by default.
 
**Primitive types can always be extended by record helpers in Delphi modes.
 
**The modeswitch enables the ''type helper''-syntax as known from non-Delphi modes.
 
* '''Reason''': The previous implementation of the modeswitch was illogical additionally there were user wishes to allow inheritance for record helpers in Delphi modes.
 
* '''Remedy''': The only problems arise if one disabled the modeswitch on purpose which now no longer disallows the extension of primitive types.
 
* '''svn''': 37225
 
 
==== Class references in a class VMT's field table ====
 
* '''Old behaviour''': The class array of the vFieldTable of the VMT contains an array of TClass entries
 
* '''New behaviour''': The class array of the vFieldTable of the VMT contains an array of PClass entries
 
* '''Reason''': As for the RTTI the indirect references are necessary for dynamic packages.
 
* '''Remedy''': Use an additional dereferentiation to access the class type.
 
* '''svn''': 37485
 
  
 
=== Language Changes ===
 
=== Language Changes ===
  
==== Visibility of generic type parameters ====
+
==== Precedence of the IS operator changed ====
* '''Old behaviour''': Type parameters of generics had ''public'' visibility.
+
* '''Old behaviour''': The IS operator had the same predence as the multiplication, division etc. operators.
* '''New behaviour''': Type parameters of generics now have ''strict private'' visibility.
+
* '''New behaviour''': The IS operator has the same predence as the comparison operators.
* '''Reason''': With the previous visibility it was possible to create code that leads to infinite loops during compilation or other hard to debug errors. In addition there is no real possibility to work around this issue (for an example see [http://bugs.freepascal.org/view.php?id=25917 this] bug report). Also the fix is Delphi compatible.
+
* '''Reason''': Bug, see [https://bugs.freepascal.org/view.php?id=35909].
* '''Remedy''': Declare a type alias for the type parameter with the desired visibility.
+
* '''Remedy''': Add parenthesis where needed.
* '''Example''': In the following example ''T'' is declared as ''strict private'', while ''TAlias'' is declared as ''public'' and thus can be used as before the change.
 
<syntaxhighlight>
 
type
 
  generic TTest<T> = class
 
  public type
 
    TAlias = T;
 
  end;
 
</syntaxhighlight>
 
  
==== Parsing of ''specialize'' has been changed ====
+
=== Implementation Changes ===
* '''Old behaviour''': ''specialize'' was used to initialize a specialization and was followed by a type name that might contain a unit name and parent types.
 
* '''New behaviour''': ''specialize'' is now considered part of the specialized type, just as ''generic'' is. This means that unit names and parent types need to be used before the part containing the ''specialize''.
 
* '''Reason''': This allows for a more logical usage of ''specialize'' in context with nested types (especially if multiple specializations are involved) and more importantly generic functions and methods.
 
* '''Remedy''': Put the ''specialize'' directly in front of the type which needs to be specialized.
 
 
 
==== Operator overload ''+'' no longer allowed for dynamic arrays ====
 
* '''Old behaviour''': The ''+'' operator could be overloaded for dynamic array types.
 
* '''New behaviour''': The ''+'' operator for dynamic array types can no longer be overloaded if the modeswitch ''ArrayOperators'' is active (default in Delphi modes).
 
* '''Reason''': When the modeswitch ''ArrayOperators'' is active a ''+'' operator is now provided by the compiler itself which concatenates two arrays together.
 
* '''Remedy''':
 
** Disable the modeswitch (for Delphi modes this can be done with ''{$modeswitch ArrayOperators-}'').
 
** If your operator merely concatenates two arrays then remove the overload.
 
** If your operator does something different or more then use a different operator.
 
* '''Note''': A warning is provided by the compiler if an overload is in scope, but not used due to the internal operator.
 
 
 
==== Generic type parameters need to match ====
 
* '''Old behaviour''': When defining the method of a generic class or record it was possible to use different names for the type parameters than those that were used in the declaration.
 
* '''New behaviour''': The order and name of generic type parameters of the class or record type in the method definition has to match the order and name of generic types parameters of the class or record declaration.
 
* '''Reason''': To avoid the user making mistakes e.g. when the order of parameters is swapped. Also this is compatible to at least newer Delphi versions.
 
* '''Remedy''': Use the correct generic type parameters for the definition.
 
* '''svn''': 39701
 
 
 
==== Visibility of methods implementing interface methods ====
 
* '''Old behaviour''': All methods in a class hierarchy were considered when looking for methods to implement interfaces
 
* '''New behaviour''': Only methods visible in the class that is declared as implementing the method are considered.
 
* '''Reason''': The symbol visibility rules should be respected in all cases. This fix is Delphi-compatible.
 
* '''Remedy''': Make (strict) private methods that should implement interface methods in descendant classes protected or public.
 
* '''svn''': 40645
 
  
 
==== Property field access lists no longer allows classes ====
 
==== Property field access lists no longer allows classes ====
Line 102: Line 28:
 
** Switch the fields to records or objects
 
** Switch the fields to records or objects
 
** Use a method with inline modifier that will result in similar performance
 
** Use a method with inline modifier that will result in similar performance
* '''svn''': 40646
+
* '''svn''': 40656
 
* '''Example''': The following code now fails:
 
* '''Example''': The following code now fails:
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
 
unit Test;
 
unit Test;
 
{$mode objfpc}
 
{$mode objfpc}
Line 127: Line 53:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==== Methods implementing interface methods and overloads ====
+
==== Disabled default support for automatic conversions of regular arrays to dynamic arrays ====
* '''Old behaviour''': All methods in a class hierarchy were considered when looking for methods to implement interfaces.
+
* '''Old behaviour''': In FPC and ObjFPC modes, by default the compiler could automatically convert a regular array to a dynamic array.
* '''New behaviour''': In case of overloads, searching stops when a method is found that has the right name but not the ''overload'' directive. Note that this directive is automatically inherited when overriding a method.
+
* '''New behaviour''': By default, the compiler no longer automatically converts regular arrays to dynamic arrays in any syntax mode.
* '''Reason''': The same happens when calling a method, and the symbol resolution rules should be the same in all cases. This fix is Delphi-compatible.
+
* '''Reason''': When passing a dynamic array by value, modifications to its contents by the callee are also visible on the caller side. However, if an array is implicitly converted to a dynamic array, the result is a temporary value and hence changes are lost. This issue came up when adding [https://bugs.freepascal.org/view.php?id=35580 TStream.Read() overloads].
* '''Remedy''': Add an ''overload'' directive to methods of which all overloads should be visible in the entire class hierarchy.
+
* '''Remedy''': Either change the code so it no longer assigns regular arrays to dynamic arrays, or add ''{$modeswitch arraytodynarray}'' a
* '''Example''':
+
* '''Example''': this program demonstrates the issue that appeared with the TStream.Read() overloads that were added (originally, only the the version with the untyped variable existed)
** [https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tests/webtbs/tw27349.pp?r1=40683&r2=40682&pathrev=40683 Bug found by this change] (previously, on non-Windows platforms the '''_Addref''' method of ''TInterfacedObject'' was selected for implementing by the classes implementing ''tmyintf'').
 
** [https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tests/tbf/tb0267.pp?view=markup Example that no longer compiles].
 
** [https://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/tests/tbs/tb0654.pp?view=markup Fixed example].
 
* '''svn''': 40683
 
  
=== RTTI changes ===
+
<syntaxhighlight lang="pascal">
 +
{$mode objfpc}
 +
type
 +
  tdynarray = array of byte;
  
==== RTTI for Interfaces (published property count) ====
+
procedure test(var arr); overload;
* '''Old behavior''': The property RTTI data of an interface (both COM and Corba) immediately followed the TTypeData record without any count.
+
begin
* '''New behavior''': Before the property RTTI data is now a Word count field that specifies the amount of properties
+
  pbyte(arr)[0]:=1;
* '''Reason''': Both user request and usability.
+
end;
* '''Remedy''': Adjust pointer offsets accessing the property data accordingly.
 
  
==== RTTI for COM Interfaces (IID String) ====
+
procedure test(arr: tdynarray); overload;
* '''Old behavior''': COM interfaces contain an undocumented IIDStr between the unit name IntfUnit and the property data.
+
begin
* '''New behavior''': The undocumented field has been removed.
+
  test[0]:=1;
* '''Reason''': The IID of COM interfaces can always be represented as GUID, thus the undocumented IIDStr field is redundant.
+
end;
* '''Remedy''': Use the GUID field and convert that to a String.
 
  
==== RTTI Binary format change ====
+
var
* '''Old behavior''': References to other types are designated by PTypeInfo.
+
  regulararray: array[1..1] of byte;
* '''New behavior''': References to other types are designated by PPTypeInfo.
+
begin
* '''Reason''': While the change in the binary format is Delphi-compatible the reason for this is the introduction of the support for dynamic packages and the rules of the PE file format (Windows) that need to be played by.
+
  regulararray[1]:=0;
* '''Remedy''': If you don't access the binary data directly then there should be no change necessary. Otherwise you need to add in a further derefentiation.
+
  test(arr);
* '''Note''':  
+
  writeln(arr[0]); // writes 0, because it calls test(tdynarr)
**The PPTypeInfo value itself will be Nil if there's no reference, not the PTypeInfo reference stored in it.
+
end.
**This does not apply to TObject.ClassInfo which still returns a PTypeInfo
+
</syntaxhighlight>
 +
* '''svn''': 42118
  
==== RTTI for Corba Interfaces (IID String) ====
+
==== Range checking for enumeration constants in Delphi mode ====
* '''Old behavior''': IIDStr is a field of TTypeData.
+
* '''Old behaviour''': Out-of-range enumeration constants never caused an error in Delphi mode, because very early versions of Delphi did not either.
* '''New behavior''': IIDStr is a property of TTypeData.
+
* '''New behaviour''': Out-of-range enumeration constants cause an error in Delphi mode, even if range checking is disabled. Current Delphi versions (and even older ones, such as Delphi 7) behave the same.
* '''Reason''': The compiler assumes the RawIntfUnit field immediately preceding IIDStr is a ShortString of length 255 despite the corresponding binary data only having the length of the string it contains, thus accessing incorrect data.
+
* '''Reason''': Delphi-compatibility.
* '''Remedy''': If you merely accessed the data nothing changes, but the data following IIDStr needs to be accessed differently as RawIntfUnit is the last visible field.
+
* '''Remedy''': Fix the range errors.
* '''svn''': 35026
+
* '''svn''': 42272, 42275
  
==== Reference to Record Init Information ====
+
==== Directive clause ''[…]'' no longer useable with modeswitch ''PrefixedAttributes'' ====
* '''Old behavior''': Field RecSize follows directly after start of TTypeData record.
+
* '''Old behaviour''': A function/procedure/method or procedure/method variable type could be followed by a directive clause in square brackets (''[…]'') that contains the directives for the routine or type (e.g. calling convention).
* '''New behavior''': Field RecSize is preceeded by pointer field RecInitInfo which points to a TTypeInfo for the record init information (the TTypeInfo for that is followed by TRecInitData).
+
* '''New behaviour''': If the modeswitch ''PrefixedAttributes'' is enabled (which is the default in modes ''Delphi'' and ''DelphiUnicode'') the directive clause in square brackets is no longer allowed.
* '''Reason''': With the record init information one can more quickly decide whehther a record needs to be classed as ''managed'' or not which is among others useful for the IsManaged() function of the Rtti unit.
+
* '''Reason''': As custom attributes are bound to a type/property in a way that looks ambiguous to a directive clause and this ambiguity is not easily solved in the parser it is better to disable this feature.
* '''Remedy''': If you relied on the relative position of RecSize in TTypeData you'll need to adjust your code.
+
* '''Remedy''':
* '''Note''': The TRecInitData shares its first three fields with a record's TTypeData with the difference that the pointer to the init information is Nil.
+
** don't set (in non-''Delphi'' modes) or disable modeswitch ''PrefixedAttributes'' (in ''Delphi'' modes) if you don't use attributes (''{$modeswitch PrefixedAttributes-}'')
* '''svn''': 35125, 35134
+
** rework your directive clause:
 +
<syntaxhighlight lang="pascal">
 +
// this
 +
procedure Test; cdecl; [public,alias:'foo']
 +
begin
 +
end;
  
==== TOrdType extended ====
+
// becomes this
* '''Old behavior''': TOrdType contains entries for 8-, 16- and 32-bit widths.
+
procedure Test; cdecl; public; alias:'foo';
* '''New behavior''': TOrdType contains entries for 8-, 16-, 32- and 64-bit widths.
+
begin
* '''Reason''': Without extending TOrdType it wouldn't be possible to correctly represent Boolean type of 64-bit width as they couldn't be differentiated from ordinary Integers with a minimum of 0 and maximum of 1 for the Pascal Boolean type and minium of -1 and maximum of 0 for the Windows Boolean type.
+
end;
* '''Remedy''': Adjust arrays that have TOrdType as index.
+
</syntaxhighlight>
* '''svn''': 35135
+
* '''svn''': 42402
  
==== New OrdType field for tkInt64 and tkQWord ====
+
==== Type information contains reference to attribute table ====
* '''Old behavior''': MinInt64Value and MinQWordValue follow directly after start of TTypeData record.
+
* '''Old behavior''': The first field of the data represented by ''TTypeData'' is whatever the sub branch of the case statement for the type contains.
* '''New behavior''': MinInt64Value and MinQWordValue are preceeded by a OrdType field which explicitely designates them as otSQWord or otUQword respectively.
+
* '''New behavior''': The first field of the data represented by ''TTypeData'' is a reference to the custom attributes that are attributed to the type, only then the type specific fields follow.
* '''Reason''': To allow for 64-bit Booleans to be represented correctly the tkInt64 and tkQWord branches of TTypeData had to become part of the tkInteger (aka Ordinal) branch and thus they gained the OrdType field.
+
* '''Reason''': Any type can have attributes, so it make sense to provide this is a common location instead of having to parse the different types.
* '''Remedy''': If your code relied on the relative position of MinInt64Value and MinQWordValue towards the start of the TTypeData record it needs to be adjusted.
+
* '''Remedy''':
* '''svn''': 35135
+
** If you use the records provided by the ''TypInfo'' unit no changes ''should'' be necessary (same for the ''Rtti'' unit).
 +
** If you directly access the binary data you need handle an additional ''Pointer'' field at the beginning of the ''TTypeData'' area and possibly correct the alignment for platforms that have strict alignment requirements (e.g. ARM or M68k).
 +
* '''svn''': 42375
 +
==== Explicit values for enumeration types are limited to low(longint) ... high(longint) ====
 +
* '''Old behavior''': The compiler accepted every integer value as explicit enumeration value. The value was silently reduced to the longint range if it fell outside of that range
 +
* '''New behavior''': The compiler throws an error (FPC mode) or a warning (Delphi mode) if an explicit enumeration value lies outside the longint range.
 +
* '''Reason''': ''Type TEnum = (a = $ffffffff);'' resulted in an enum with size 1 instead of 4 as would be expected, because  $ffffffff was interpreted as "-1".
 +
* '''Remedy''': Add Longint typecasts to values outside the valid range of a Longint.
  
==== First field of TProcedureParam changed ====
+
==== Comp as a type rename of Int64 instead of an alias ====
* '''Old behavior''': First field of TProcedureParam is called Flags and has type Byte.
+
* '''Old behavior''': On non-x86 as well as Win64 the Comp type is declared as an alias to Int64 (''Comp = Int64'').
* '''New behavior''': First field of TProcedureParam is called ParamFlags and has type TParamFlags and there is a property called Flags of type Byte.
+
* '''New behavior''': On non-x86 as well as Win64 the Comp type is declared as a type rename of Int64 (''Comp = type Int64'').
* '''Reason''': Since TParamFlags is a set it might grow beyond the size of a Byte if more values are added to TParamFlag.
+
* '''Reason''':
* '''Remedy''': Most code should be able to use the backwards and Delphi compatible Flags property (at least if it only wants to check TParamFlag values of which the ordinal value is less than 8) other code should switch to using ParamFlags.
+
** This allows overloads of ''Comp'' and ''Int64'' methods/functions
* '''svn''': 35174
+
** This allows to better detect properties of type ''Comp''
 
+
** Compatibility with Delphi for Win64 which applied the same reasoning
==== TParamFlag extended for constref ====
+
* '''Remedy''': If you relied on ''Comp'' being able to be passed to ''Int64'' variables/parameters either include typecasts or add overloads for ''Comp''.
* '''Old behavior''': TParamFlag has no entry for constref parameters.
+
* '''svn''': 43775
* '''New behavior''': TParamFlag has entry pfConstRef for constref parameters.
 
* '''Reason''': To correctly detect constref parameters they need to be marked accordingly.
 
* '''Remedy''': Adjust code that relies on the amount of elements contained in TParamFlag (e.g. case-statements or array indices).
 
* '''svn''': 35175
 
 
 
==== Ranges of Boolean types adjusted ====
 
* '''Old behavior''': ByteBool, WordBool and LongBool have a range of 0..-1.
 
* '''New behavior''': ByteBool, WordBool and LongBool have a range of Low(LongInt) to High(LongInt).
 
* '''Reason''': The old behavior simply cut the Low(Int64) and High(Int64) values used as ranges for the Boolean types which was wrong. That the ranges are not size dependant is Delphi compatible.
 
* '''Remedy''': Adjust code that might have relied on the range being ''invalid''.
 
* '''svn''': 35184
 
 
 
==== OrdType of Boolean64 and QWordBool adjusted ====
 
* '''Old behavior''': Boolean64 has OrdType otUByte and QWordBool has OrdType otSByte and their ranges are in MinValue and MaxValue.
 
* '''New behavior''': Boolean64 has OrdType otUQWord with the range being in MinQWordValue and MaxQWordValue and QWordBool has OrdType otSQWord with the range being in MinInt64Value and MaxInt64Value.
 
* '''Reason''': Both types have a size of 64-bit thus using a smaller size is incorrect.
 
* '''Remedy''': Use the correct fields to retrieve the range boundaries of the types.
 
* '''svn''': 35185
 
 
 
==== All Boolean types have TypeKind tkBool ====
 
* '''Old behavior''': Boolean has TypeKind tkBool while the other Boolean types (Boolean16, Boolean32, Boolean64, ByteBool, WordBool, LongBool, QWordBool) have TypeKind tkInteger.
 
* '''New behavior''': Boolean, Boolean16, Boolean32, Boolean64, ByteBool, WordBool, LongBool and QWordBool have TypeKind tkBool.
 
* '''Reason''': Consistency and possibility to differentiate ordinary subranges from the real Boolean types.
 
* '''Remedy''': Check for TypeKind tkBool instead of some "magic" to detect Boolean types.
 
* '''Note''': Since fields can only appear once in a record the tkBool branch of TTypeData was not adjusted. This has no practical consequences however as all fields of a variant record are always accessible.
 
* '''svn''': 35186, 35187
 
 
 
==== TParamFlag extended for hidden parameters ====
 
* '''Old behavior''': TParamFlag has no entries for the hidden parameters (Array High, Self, Vmt, Result) of a function; SizeOf(TParamFlags) = 1
 
* '''New behavior''': TParamFlag has entry pfHidden for hidden parameters in general and pfHigh for the high parameter of open array, pfSelf for the instance or class type, pfVmt for constructor's VMT parameter and pfResult if the result is passed as a parameter; SizeOf(TParamFlags) = 2
 
* '''Reason''': As the plan is to use a manager based approach for Invoke() the RTL glue code should need as less knowledge as possible about calling conventions; due to this the locations of the hidden parameters needs to be known.
 
* '''Remedy''': Adjust code that relies on the amount of elements contained in TParamFlag (e.g. case-statements or array indices) and also code that relies on the size of TParamFlags being 1 (SizeOf(TParamFlags) should be used instead).
 
* '''svn''': 35267, 35286, 35291
 
 
 
==== Parameters of method pointer variables contain hidden parameters ====
 
* '''Old behavior''': The parameters of method pointer variables only listed visible parameters.
 
* '''New behavior''': The parameters of method pointer variables list all parameters.
 
* '''Reason''': Makes the implementation of function call managers more stable in case the ABI should change.
 
* '''Remedy''': Depending on your code either handle the new parameters or check for ''pfHidden'' in the parameter flags and ignore them.
 
* '''svn''': 39885
 
 
 
==== Parameters of procedure variables contain hidden parameters ====
 
* '''Old behavior''': The parameters of procedure variables only listed visible parameters.
 
* '''New behavior''': The parameters of procedure variables list all parameters.
 
* '''Reason''': Makes the implementation of function call managers more stable in case the ABI should change.
 
* '''Remedy''': Depending on your code either handle the new parameters or check for ''pfHidden'' in the parameter flags and ignore them.
 
* '''svn''': 39885
 
  
 
=== Unit changes ===
 
=== Unit changes ===
  
==== System ====
+
==== System - TVariantManager ====
  
 
* '''Old behaviour:''' ''TVariantManager.olevarfromint'' has a ''source'' parameter of type ''LongInt''.
 
* '''Old behaviour:''' ''TVariantManager.olevarfromint'' has a ''source'' parameter of type ''LongInt''.
 
* '''New behaviour:''' ''TVariantManager.olevarfromint'' has a ''source'' parameter of type ''Int64''.
 
* '''New behaviour:''' ''TVariantManager.olevarfromint'' has a ''source'' parameter of type ''Int64''.
* '''Reason for change:''' 64-bit values couldn't be correctly converted to a OleVariant.
+
* '''Reason for change:''' 64-bit values couldn't be correctly converted to an OleVariant.
 
* '''Remedy:''' If you implemented your own variant manager then adjust the method signature and handle the range parameter accordingly.
 
* '''Remedy:''' If you implemented your own variant manager then adjust the method signature and handle the range parameter accordingly.
 +
* '''svn:''' 41570
  
==== SysUtils ====
+
==== 64-bit values in OleVariant ====
* '''Old behaviour:''' faSymlink had the numerical value $40. This was wrong on windows, and not compatible with Delphi.
 
* '''New behaviour:''' faSymlink has the numerical value $400. Correct on windows.
 
* '''Reason for change:''' Wrong functionality and Delphi compatibility.
 
* '''Remedy:''' If you are using the old numerical constant $40, simply use faSymlink instead.
 
  
===== TList auto-growth =====
+
* '''Old behaviour:''' If a 64-bit value (''Int64'', ''QWord'') is assigned to an OleVariant its type is ''varInteger'' and only the lower 32-bit are available.
* '''Old behaviour:''' Lists with number of elements greater than 127 was expanded by 1/4 of its current capacity
+
* '''New behaviour:''' If a 64-bit value (''Int64'', ''QWord'') is assigned to an OleVariant its type is either ''varInt64'' or ''varQWord'' depending on the input type.
* '''New behaviour:''' Adds two new thresholds. If number of elements is greater than 128 MB then list is expanded by constant amount of 16 MB elements (corresponds to 1/8 of 128 MB). If number of elements is greater then 8 MB then list is expanded by 1/8 of its current capacity.
+
* '''Reason for change:''' 64-bit values weren't correctly represented. This change is also Delphi compatible.
* '''Reason for change:''' Avoid out-of-memory when very large lists are expanded
+
* '''Remedy:''' Ensure that you handle 64-bit values correctly when using OleVariant.
 +
* '''svn:''' 41571
  
==== StrUtils AnsiStartsText/AnsiEndsText ====
+
==== Classes TCollection.Move ====
* '''Old behaviour:''' AnsiStartsText or AnsiEndsText would return false for empty substring. This is not in line with Delphi, which returns true.
+
* '''Old behaviour:''' If a TCollection.Descendant called Move() this would invoke System.Move.
* '''New behaviour:''' AnsiStartsText or AnsiEndsText now return True for empty substring.
+
* '''New behaviour:''' If a TCollection.Descendant called Move() this invokes TCollection.Move.
* '''Reason for change:''' Delphi compatibility.
+
* '''Reason for change:''' New feature in TCollection: move, for consistency with other classes.
* '''Remedy:''' Check explicitly for empty string if you counted on the old behaviour.
+
* '''Remedy:''' prepend the Move() call with the system unit name: System.move().
 +
* '''svn:''' 41795
  
==== Classes IStreamAdaptor ====
+
==== Math Min/MaxSingle/Double ====
* '''Old behaviour:''' ISTreamAdaptor Interface (classes unit and jwa units) used Int64 for various out parameters.
+
* '''Old behaviour:''' MinSingle/MaxSingle/MinDouble/MaxDouble were set to a small/big value close to the smallest/biggest possible value.
* '''New behaviour:''' ISTreamAdaptor Interface (classes unit and jwa units) use QWord for various out parameters.
+
* '''New behaviour:''' The constants represent now the smallest/biggest positive normal numbers.
* '''Reason for change:''' The MS Headers use largeUint, which translates to QWord. The headers were for an old version of Delphi, which didn't know QWord.
+
* '''Reason for change:''' Consistency (this is also Delphi compatibility), see https://bugs.freepascal.org/view.php?id=36870.
* '''Remedy:''' If a class implementing this interface no longer compiles, adapt the signature of the interface's methods so they conform to the new definition.
+
* '''Remedy:''' If the code really depends on the old values, rename them and use them as renamed.
 +
* '''svn:''' 44714
  
==== Baseunix (Linux only) ====
 
* '''Old behaviour:''' stat was an union, with one side the proper posix fieldnames, and the other deprecated, simplified 1.0.x fieldnames.  The 1.0.x were already marked as deprecated for 2 major cycles.
 
* '''New behaviour:''' Deprecated 1.0.x fieldnames removed.
 
* '''Reason for change:''' Left over 1.0.x transition feature. Incompatible with other *nix ports.
 
* '''Remedy:''' Update fieldnames
 
 
==== Classes TStrings.LoadFromStream/File encoding handling  ====
 
* '''Old behaviour:''' The LoadFromStream call totally ignored the encoding of a file, loading it from a stream without regard for encoding, unless an encoding was specified.
 
* '''New behaviour:''' There is an overloaded call with a Boolean parameter 'IgnoreEncoding' which determines whether the encoding should be taken into account or not. By default, this parameter is False, meaning that LoadFromStream with just a stream as argument now calls the encoding-aware version of LoadFromStream, passing it an encoding of Nil, which mean the default encoding will be used.
 
* '''Reason for change:''' Delphi compatibility, and the corresponding changes in TStringStream constructors.
 
* '''Remedy:''' The old behaviour can be restored by setting the IgnoreEncoding parameter to 'True'.
 
 
===== TStringStream now observe system encoding =====
 
* '''Old behaviour''': TStringStream copied bytes as-is from the string specified in the constructor.
 
* '''New behaviour''': Now bytes are fetched from the string using the encoding of the string.
 
 
==== DB ====
 
==== DB ====
===== TParam.LoadFromFile sets share mode to fmShareDenyWrite =====
+
===== TMSSQLConnection uses TDS protocol version 7.3 (MS SQL Server 2008) =====
* '''Old behaviour''': TFileStream.Create(FileName, fmOpenRead) was used, which has blocked subsequent access (also read-only) to same file
+
* '''Old behaviour:''' TMSSQLConnection used TDS protocol version 7.0 (MS SQL Server 2000).
* '''New behaviour''': TFileStream.Create(FileName, fmOpenRead+fmShareDenyWrite) is used, which does not block read access to same file
+
* '''New behaviour:''' TMSSQLConnection uses TDS protocol version 7.3 (MS SQL Server 2008).
* '''Remedy''': If your application requires exclusive access to file specify fmShareExclusive
+
* '''Reason for change:''' native support for new data types introduced in MS SQL Server 2008 (like DATE, TIME, DATETIME2). FreeTDS client library version 0.95 or higher required.
 
+
* '''svn''': 42737
===== CodePage aware TStringField and TMemoField =====
 
* '''Old behaviour''': These character fields were agnostic to data they presented. IOW when we read content of such field using AsString data was passed from internal character buffer to string as is without any conversion.
 
* '''New behaviour''': When those fields are created there can be specified CodePage (if none specified CP_ACP is assumed), which defines encoding of character data presented by this field. In case of sqlDB TSQLConnection.CharSet is usualy used. When we read content of such field using AsString character data are translated from fields code page to CP_ACP. Same translation happens when we read content using AsUTF8String (translation to CP_UTF8) or AsUnicodeString (translation to UTF-16). This change reflects CodePage aware strings introduced in FPC 3.
 
 
 
===== ODBC headers on Unix platforms defaults to 3.52 version =====
 
* '''Old behaviour''': default was ODBCVER $0351. SQLLEN/SQLULEN was 32 bit on 64 bit Unix platforms.
 
* '''New behaviour''': default is  ODBCVER $0352. SQLLEN/SQLULEN is 64 bit on 64 bit Unix platforms. So it affects some ODBC API functions, which use parameters of this type (it affects also TODBCConnection of course). Also installed unixODBC/iODBC package must match this (in case of unixODBC you can check it using: "odbcinst -j" SQLLEN/SQLULEN must be 8 bytes on 64 bit platform).
 
 
 
===== TBlobData opaque type reworked to TBytes =====
 
* '''Old behaviour''': TBlobData was declared as Ansistring
 
* '''New behaviour''': TBlobData is declared as TBytes 
 
* '''Reason for change''': Delphi compatibility. Also helps to avoid possible code page recodings.
 
* '''Remedy''': If your application used TBlobData as a string, you can use AsString for parameters, or convert to TBytes.
 
 
 
==== FGL ====
 
===== Declaration of type TTypeList changed =====
 
* '''Old behavior''': The type ''TTypeList'' of the generic classes ''TFPGList<>'', ''TFPGObjectList<>'' and ''TFPGInterfacedObjectList<>'' is declared as ''array[0..GMaxListSize] of T''.
 
* '''New behavior''': The type ''TTypeList'' of the generic classes ''TFPGList<>'', ''TFPGObjectList<>'' and ''TFPGInterfacedObjectList<>'' is declared as ''PT''.
 
* '''Reason''': The way ''GMaxListSize'' was declared this could lead to too large static array types so that compilation aborted with a ''Data segment too large'' error. This also might have lead to incorrect range errors if range checking was turned on. As FPC supports indexed access to pointer types potential type problems when using the ''List'' property should be minimal.
 
* '''Remedy''': If your application relies on ''PTypeList'' to be a static array type (instead of merely being indexable like an array) then you'll need to adjust your code.
 
 
 
== Linux/Android platforms ==
 
 
 
=== GNU Binutils 2.19.1 or later are required by default ===
 
* '''Old behaviour''': The compiler invocation of the linker always resulted in a warning stating "did you forget -T?"
 
* '''New behaviour''': The compiler now uses a different way to invoke the linker, which prevents this warning, but this requires functionality that is only available in GNU Binutils 2.19 and later.
 
* '''Reason''': Get rid of the linker warning, which was caused by the fact that we used the linker in an unsupported way (and which hence occasionally caused issues).
 
* '''Remedy''': If you have a system with an older version of GNU Binutils, you can use the new ''-X9'' command line parameter to make the compiler revert to the old behaviour. You will not be able to (easily) bootstrap the new version of FPC on such a system though, so use another system with a more up-to-date version of GNU Binutils for that.
 
 
 
== i386 platforms ==
 
 
 
=== -Ooasmcse/{$optimization asmcse} has been removed ===
 
* '''Old behaviour''': The compiler contained an assembler common subexpression elimination pass for the i386 platform.
 
* '''New behaviour''': This optimisation pass has been removed from the compiler.
 
* '''Reason''': That pass has been disabled by default since several releases because it hadn't been maintained, and it generated buggy code when combined with newer optimisation passes.
 
* '''Remedy''': Don't use -Ooasmcse/{$optimization asmcse} anymore.
 
 
 
== i8086 platforms ==
 
 
 
=== the codepointer type has been changed in the small and compact memory models ===
 
 
 
* '''Old behaviour''': The compiler used the NearPointer type for getting the address of procedures, functions and labels in the small and compact memory models.
 
* '''New behaviour''': The compiler now uses the NearCsPointer type for getting the address of procedures, functions and labels in the small and compact memory models.
 
* '''Reason''': Using NearCsPointer more accurately represents the fact that code lives in a separate segment in the small memory model and also allows reading the machine code of a procedure, which might be useful in low level code.
 
* '''Remedy''': If your program uses the small memory model and needs any kind of fixing, you're very likely to get compile time type checking errors, since the Pointer and CodePointer types are no longer compatible. To fix these, change all your pointers that point to code to CodePointer instead of Pointer. Alternatively, if your program is really small (code+data<=64k), you can switch to the tiny memory model, where the Pointer and CodePointer types are still compatible. If your program uses the compact memory model, it is unlikely to get any sort of breakage, since the Pointer and CodePointer types were already incompatible in this memory model.
 
  
 
== Previous release notes ==
 
== Previous release notes ==

Revision as of 09:49, 13 April 2020

About this page

Listed below are intentional changes made to the FPC compiler (trunk) since the next upcoming release that may break existing code. The list includes reasons why these changes have been implemented, and suggestions for how you might adapt your code if you find that previously working code has been adversely affected by these recent changes.

The list of new features that do not break existing code can be found here.

Please add revision numbers to the entries from now on. This facilitates moving merged items to the user changes of a release.

All systems

Language Changes

Precedence of the IS operator changed

  • Old behaviour: The IS operator had the same predence as the multiplication, division etc. operators.
  • New behaviour: The IS operator has the same predence as the comparison operators.
  • Reason: Bug, see [1].
  • Remedy: Add parenthesis where needed.

Implementation Changes

Property field access lists no longer allows classes

  • Old behaviour: A field access list for a property is allowed to contain implicit dereferences in the form of fields of class instances.
  • New behaviour: A field access list for a property must only contain record or (TP style) object fields.
  • Reason:
    • Delphi compatibility
    • This resulted in an internal error for published properties
  • Remedy:
    • Switch the fields to records or objects
    • Use a method with inline modifier that will result in similar performance
  • svn: 40656
  • Example: The following code now fails:
unit Test;
{$mode objfpc}

interface

type
  TTest1 = class
    Field: String;
  end;

  TTest2 = class
  private
    fTest1: TTest1;
  public
    property Prop: String read fTest1.Field; // Error "Record or object type expected"
  end;

implementation

end.

Disabled default support for automatic conversions of regular arrays to dynamic arrays

  • Old behaviour: In FPC and ObjFPC modes, by default the compiler could automatically convert a regular array to a dynamic array.
  • New behaviour: By default, the compiler no longer automatically converts regular arrays to dynamic arrays in any syntax mode.
  • Reason: When passing a dynamic array by value, modifications to its contents by the callee are also visible on the caller side. However, if an array is implicitly converted to a dynamic array, the result is a temporary value and hence changes are lost. This issue came up when adding TStream.Read() overloads.
  • Remedy: Either change the code so it no longer assigns regular arrays to dynamic arrays, or add {$modeswitch arraytodynarray} a
  • Example: this program demonstrates the issue that appeared with the TStream.Read() overloads that were added (originally, only the the version with the untyped variable existed)
{$mode objfpc}
type
  tdynarray = array of byte;

procedure test(var arr); overload;
begin
  pbyte(arr)[0]:=1;
end;

procedure test(arr: tdynarray); overload;
begin
  test[0]:=1;
end;

var
  regulararray: array[1..1] of byte;
begin
  regulararray[1]:=0;
  test(arr);
  writeln(arr[0]); // writes 0, because it calls test(tdynarr)
end.
  • svn: 42118

Range checking for enumeration constants in Delphi mode

  • Old behaviour: Out-of-range enumeration constants never caused an error in Delphi mode, because very early versions of Delphi did not either.
  • New behaviour: Out-of-range enumeration constants cause an error in Delphi mode, even if range checking is disabled. Current Delphi versions (and even older ones, such as Delphi 7) behave the same.
  • Reason: Delphi-compatibility.
  • Remedy: Fix the range errors.
  • svn: 42272, 42275

Directive clause […] no longer useable with modeswitch PrefixedAttributes

  • Old behaviour: A function/procedure/method or procedure/method variable type could be followed by a directive clause in square brackets ([…]) that contains the directives for the routine or type (e.g. calling convention).
  • New behaviour: If the modeswitch PrefixedAttributes is enabled (which is the default in modes Delphi and DelphiUnicode) the directive clause in square brackets is no longer allowed.
  • Reason: As custom attributes are bound to a type/property in a way that looks ambiguous to a directive clause and this ambiguity is not easily solved in the parser it is better to disable this feature.
  • Remedy:
    • don't set (in non-Delphi modes) or disable modeswitch PrefixedAttributes (in Delphi modes) if you don't use attributes ({$modeswitch PrefixedAttributes-})
    • rework your directive clause:
// this
procedure Test; cdecl; [public,alias:'foo']
begin
end;

// becomes this
procedure Test; cdecl; public; alias:'foo';
begin
end;
  • svn: 42402

Type information contains reference to attribute table

  • Old behavior: The first field of the data represented by TTypeData is whatever the sub branch of the case statement for the type contains.
  • New behavior: The first field of the data represented by TTypeData is a reference to the custom attributes that are attributed to the type, only then the type specific fields follow.
  • Reason: Any type can have attributes, so it make sense to provide this is a common location instead of having to parse the different types.
  • Remedy:
    • If you use the records provided by the TypInfo unit no changes should be necessary (same for the Rtti unit).
    • If you directly access the binary data you need handle an additional Pointer field at the beginning of the TTypeData area and possibly correct the alignment for platforms that have strict alignment requirements (e.g. ARM or M68k).
  • svn: 42375

Explicit values for enumeration types are limited to low(longint) ... high(longint)

  • Old behavior: The compiler accepted every integer value as explicit enumeration value. The value was silently reduced to the longint range if it fell outside of that range
  • New behavior: The compiler throws an error (FPC mode) or a warning (Delphi mode) if an explicit enumeration value lies outside the longint range.
  • Reason: Type TEnum = (a = $ffffffff); resulted in an enum with size 1 instead of 4 as would be expected, because $ffffffff was interpreted as "-1".
  • Remedy: Add Longint typecasts to values outside the valid range of a Longint.

Comp as a type rename of Int64 instead of an alias

  • Old behavior: On non-x86 as well as Win64 the Comp type is declared as an alias to Int64 (Comp = Int64).
  • New behavior: On non-x86 as well as Win64 the Comp type is declared as a type rename of Int64 (Comp = type Int64).
  • Reason:
    • This allows overloads of Comp and Int64 methods/functions
    • This allows to better detect properties of type Comp
    • Compatibility with Delphi for Win64 which applied the same reasoning
  • Remedy: If you relied on Comp being able to be passed to Int64 variables/parameters either include typecasts or add overloads for Comp.
  • svn: 43775

Unit changes

System - TVariantManager

  • Old behaviour: TVariantManager.olevarfromint has a source parameter of type LongInt.
  • New behaviour: TVariantManager.olevarfromint has a source parameter of type Int64.
  • Reason for change: 64-bit values couldn't be correctly converted to an OleVariant.
  • Remedy: If you implemented your own variant manager then adjust the method signature and handle the range parameter accordingly.
  • svn: 41570

64-bit values in OleVariant

  • Old behaviour: If a 64-bit value (Int64, QWord) is assigned to an OleVariant its type is varInteger and only the lower 32-bit are available.
  • New behaviour: If a 64-bit value (Int64, QWord) is assigned to an OleVariant its type is either varInt64 or varQWord depending on the input type.
  • Reason for change: 64-bit values weren't correctly represented. This change is also Delphi compatible.
  • Remedy: Ensure that you handle 64-bit values correctly when using OleVariant.
  • svn: 41571

Classes TCollection.Move

  • Old behaviour: If a TCollection.Descendant called Move() this would invoke System.Move.
  • New behaviour: If a TCollection.Descendant called Move() this invokes TCollection.Move.
  • Reason for change: New feature in TCollection: move, for consistency with other classes.
  • Remedy: prepend the Move() call with the system unit name: System.move().
  • svn: 41795

Math Min/MaxSingle/Double

  • Old behaviour: MinSingle/MaxSingle/MinDouble/MaxDouble were set to a small/big value close to the smallest/biggest possible value.
  • New behaviour: The constants represent now the smallest/biggest positive normal numbers.
  • Reason for change: Consistency (this is also Delphi compatibility), see https://bugs.freepascal.org/view.php?id=36870.
  • Remedy: If the code really depends on the old values, rename them and use them as renamed.
  • svn: 44714

DB

TMSSQLConnection uses TDS protocol version 7.3 (MS SQL Server 2008)
  • Old behaviour: TMSSQLConnection used TDS protocol version 7.0 (MS SQL Server 2000).
  • New behaviour: TMSSQLConnection uses TDS protocol version 7.3 (MS SQL Server 2008).
  • Reason for change: native support for new data types introduced in MS SQL Server 2008 (like DATE, TIME, DATETIME2). FreeTDS client library version 0.95 or higher required.
  • svn: 42737

Previous release notes