* fix for Mantis #32111: allow undefined defs as a for loop's counter; the specialization will decide whether it will compile or not

+ added test

git-svn-id: trunk@36722 -
This commit is contained in:
svenbarth 2017-07-10 19:45:15 +00:00
parent b884ab31fa
commit ca78bfffae
3 changed files with 66 additions and 3 deletions

1
.gitattributes vendored
View File

@ -15628,6 +15628,7 @@ tests/webtbs/tw31945.pp svneol=native#text/pascal
tests/webtbs/tw3197.pp svneol=native#text/plain
tests/webtbs/tw3207.pp svneol=native#text/plain
tests/webtbs/tw3210.pp svneol=native#text/plain
tests/webtbs/tw32111.pp svneol=native#text/pascal
tests/webtbs/tw3212.pp svneol=native#text/plain
tests/webtbs/tw3214.pp svneol=native#text/plain
tests/webtbs/tw3216.pp svneol=native#text/plain

View File

@ -375,11 +375,14 @@ implementation
loopvarsym:=nil;
{ variable must be an ordinal, int64 is not allowed for 32bit targets }
if not(is_ordinal(hloopvar.resultdef))
if (
not(is_ordinal(hloopvar.resultdef))
{$ifndef cpu64bitaddr}
or is_64bitint(hloopvar.resultdef)
or is_64bitint(hloopvar.resultdef)
{$endif not cpu64bitaddr}
then
) and
(hloopvar.resultdef.typ<>undefineddef)
then
MessagePos(hloopvar.fileinfo,type_e_ordinal_expr_expected);
hp:=hloopvar;

59
tests/webtbs/tw32111.pp Normal file
View File

@ -0,0 +1,59 @@
{ %NORUN }
program tw32111;
{$MODE OBJFPC}{$H+}{$B-}
uses
SysUtils;
type generic
TDynArray<T> = array of T;
type generic
TSorter<T, C> = class
protected
var
Tmp: C;
procedure _Sort(constref Index: specialize TDynArray<C>;
constref Values: specialize TDynArray<T>;
StartIndex, EndIndex: Int32); virtual;
public
procedure Sort(constref Index: specialize TDynArray<C>;
constref Values: specialize TDynArray<T>;
StartIndex, EndIndex: Int32); virtual;
end;
procedure TSorter.Sort(constref Index: specialize TDynArray<C>;
constref Values: specialize TDynArray<T>;
StartIndex, EndIndex: Int32);
var
Len: Int32;
I : C;
begin
// some code
Len:= System.Length(Values);
if (Len = 0) or ( Assigned(Index) and (Len <> System.Length(Index)) ) then Exit;
if Assigned(Index)
then begin
for I:= C(Startindex) to C(EndIndex) do Index[I]:= I;
I:= 1;
end;
Self._Sort(Index, Values, StartIndex, EndIndex);
end;
procedure TSorter._Sort(constref Index: specialize TDynArray<C>;
constref Values: specialize TDynArray<T>;
StartIndex, EndIndex: Int32);
begin
// some code
end;
var
s: specialize TSorter<Unicodestring, Int32>;
begin
s:= specialize TSorter<Unicodestring, Int32>.Create;
end.