[fpc-pascal] Constants in generics

Alexander Shishkin alexvins at mail.ru
Thu Jan 3 12:58:00 CET 2019


03.01.2019 6:32, Ryan Joseph пишет:
> 
> 
>> On Jan 2, 2019, at 8:25 PM, Alexander Shishkin via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> This is not consistent with constraints. Should be ";" after T.
>>
>> And what about following examples?
>>
> 
> The semicolon is only needed following a generic parameter which is constrained. This was the normal behavior before constants were introduced.
> 
> generic TMyRecord1<T: TObject; const U: integer> = record
>

It is not exactly true, semicolon separates parameter lists different 
restrictions including empty one.

This should fail to compile (": integer" restriction can not be applied 
to non const parameter):
generic TMyRecord1<T, const U: integer> = record end;
generic TMyRecord1<const T, U: integer> = record end;

This is OK (T is any type):
generic TMyRecord1<T; const U: integer> = record end;

This is OK (both T and U are integer):
generic TMyRecord1<const T, const U: integer> = record end;

This is OK (T is any const,  U and V are integer)
generic TMyRecord1<const T; const U, const V: integer> = record end;

--AVS




More information about the fpc-pascal mailing list