View Issue Details

IDProjectCategoryView StatusLast Update
0037303FPCCompilerpublic2020-08-05 17:24
Reporteravk Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86_64OSlinux 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037303: Intrinsic Default() in a generic procedure
DescriptionFPC seems to have problems using the Default() intrinsic in declarations of generic procedures/functions.
Specialization of the procedure with any non-simple type crashes the compiler.

The result of compiling the attached example:

Hint: (11030) Start of reading config file /home_dev/fpc/bin/x86_64-linux/fpc.cfg
Hint: (11031) End of reading config file /home_dev/fpc/bin/x86_64-linux/fpc.cfg
Free Pascal Compiler version 3.3.1-r45732 [2020/07/06] for x86_64
Copyright (c) 1993-2020 by Florian Klaempfl and others
(1002) Target OS: Linux for x86-64
(3104) Compiling gen_default.pas
An unhandled exception occurred at $000000000056E794:
EAccessViolation: Access violation
  $000000000056E794 GETDEFAULTVARSYM, line 456 of ninl.pas
  $000000000058154D CREATE, line 2191 of htypechk.pas
  $0000000000558101 PASS_TYPECHECK, line 3714 of ncal.pas

/home_dev/bugs/test_default/gen_default.pas(18,51) Error: (4119) It is not possible to define a default value for a parameter of type "TBla"
/home_dev/bugs/test_default/test_default.pas(18,51) Error: (1026) Compilation raised exception internally
Fatal: (1018) Compilation aborted
Error: /home_dev/fpc/bin/x86_64-linux/ppcx64 returned an error exitcode
Tagsgenerics
Fixed in Revision45772
FPCOldBugId
FPCTarget-
Attached Files

Activities

avk

2020-07-06 09:13

reporter  

gen_default.pas (537 bytes)   
program gen_default;

{$mode delphi}

uses SysUtils;

type

  TBla = record
    Bla: Integer;
  end;

  //TBla = array[1..4] of Integer;

  //TBla = type Integer;


procedure SetValue<T>(out v: T; const aValue: T = Default(T));
begin
  v := aValue;
end;

procedure Test;
var
  Bla: TBla;
begin
  SetValue<TBla>(Bla);
  WriteLn(Format('Bla = (Bla: %d)', [Bla.Bla]));
  //WriteLn(Format('Bla = (%d, %d, %d, %d)', [Bla[1], Bla[2], Bla[3], Bla[4]]));
  //WriteLn('Bla = ', Bla);
end;

begin
  Test;
end.

gen_default.pas (537 bytes)   

Florian

2020-07-12 08:24

administrator   ~0123908

The compiler does not crash anymore. I guess you don't expect that this compiles without error?

avk

2020-07-12 13:49

reporter   ~0123923

Thank you.
Now 3.3.1 works as expected: compilation error.
But what about 3.2.1?

Issue History

Date Modified Username Field Change
2020-07-06 09:13 avk New Issue
2020-07-06 09:13 avk File Added: gen_default.pas
2020-07-06 09:14 avk Tag Attached: generics
2020-07-12 08:24 Florian Assigned To => Florian
2020-07-12 08:24 Florian Status new => resolved
2020-07-12 08:24 Florian Resolution open => fixed
2020-07-12 08:24 Florian Fixed in Version => 3.3.1
2020-07-12 08:24 Florian Fixed in Revision => 45772
2020-07-12 08:24 Florian FPCTarget => -
2020-07-12 08:24 Florian Note Added: 0123908
2020-07-12 13:49 avk Note Added: 0123923
2020-08-05 17:24 avk Status resolved => closed