Merged revision(s) 42776 from trunk:

* fix for Mantis #35981: ensure that the "specialize" token is only really used in non-Delphi modes
........

git-svn-id: branches/fixes_3_2@45994 -
This commit is contained in:
svenbarth 2020-08-02 17:51:34 +00:00
parent 80553119b5
commit 52be8c6631
3 changed files with 43 additions and 2 deletions

1
.gitattributes vendored
View File

@ -15853,6 +15853,7 @@ tests/webtbf/tw3562.pp svneol=native#text/plain
tests/webtbf/tw35671.pp svneol=native#text/plain
tests/webtbf/tw35753.pp svneol=native#text/plain
tests/webtbf/tw3583.pp svneol=native#text/plain
tests/webtbf/tw35981.pp svneol=native#text/pascal
tests/webtbf/tw36114.pp svneol=native#text/pascal
tests/webtbf/tw3626.pp svneol=native#text/plain
tests/webtbf/tw3631.pp svneol=native#text/plain

View File

@ -359,7 +359,7 @@ implementation
if checkcurrentrecdef and
try_parse_structdef_nested_type(def,current_structdef,isforwarddef) then
exit;
if not allowunitsym and (idtoken=_SPECIALIZE) then
if not allowunitsym and not (m_delphi in current_settings.modeswitches) and (idtoken=_SPECIALIZE) then
begin
consume(_ID);
is_specialize:=true;
@ -490,7 +490,7 @@ implementation
_ID:
begin
if try_to_consume(_SPECIALIZE) then
if not (m_delphi in current_settings.modeswitches) and try_to_consume(_SPECIALIZE) then
begin
if ([stoAllowSpecialization,stoAllowTypeDef] * options = []) then
begin

40
tests/webtbf/tw35981.pp Normal file
View File

@ -0,0 +1,40 @@
{ %FAIL }
program tw35981;
{$mode Delphi}
uses Classes;
type
TFoo<T: TPersistent> = class(TPersistent)
public
C: T;
constructor Create;
destructor Destroy; override;
end;
constructor TFoo<T>.Create;
begin
inherited Create;
C := T.Create;
end;
destructor TFoo<T>.Destroy;
begin
C.Free;
inherited Destroy;
end;
// note the *working* specialize here, in {$mode Delphi} !!!
function Test<T: TPersistent>: specialize TFoo<T>;
begin
Result := TFoo<T>.Create;
end;
begin
with Test<TStrings> do begin
WriteLn(C.ClassName);
Free;
end;
end.