fpc/tests/webtbs/tw38145a.pp
svenbarth 66fa732720 Merged revision(s) 47634, 47655 from trunk:
* fix for Mantis #38145: allow overloading of assignment operators that return ShortStrings with a specific size
+ added tests

The following rules for using these operator overloads as *implicit* overloads apply (Delphi compatible):
  - if a found assignment operator returns a default ShortString then that is used
  - if only one assignment operator to a String[x] is found then that is used
  - otherwise the assignment is not possible
The explicit assignment checks for an exact match (and falls back for an implicit assignment). This is not entirely Delphi compatible as Delphi seems to favor the first found symbol in that case, but sometimes also not... :/
........
* with the recent ShortString changes this test is no longer needed as it was added exactly to check the condition I removed, so disable it for 3.2.1 and newer (as I want to merge these changes back to fixes)
........

git-svn-id: branches/fixes_3_2@49055 -
2021-03-26 06:18:40 +00:00

30 lines
513 B
ObjectPascal

{ %NORUN }
program tw38145a;
{$mode delphi}
type
TMyWrap<T> = record
Value: T;
class operator Explicit(const w: TMyWrap<T>): T;
class operator Implicit(const w: TMyWrap<T>): T;
end;
class operator TMyWrap<T>.Explicit(const w: TMyWrap<T>): T;
begin
Result := w.Value;
end;
class operator TMyWrap<T>.Implicit(const w: TMyWrap<T>): T;
begin
Result := w.Value;
end;
type
//TString = string[255]; //compiles
TString = string[254]; //not compiles
var
MySpec: TMyWrap<TString>;
begin
end.