Skip to content

Unexpected deprecated warning

Consider the following program:

unit Unit2;

{$mode objfpc}{$H+}

interface

uses
  Classes;

type

  TMyClass = class(TObject)
  public
    constructor Create(aParam: Integer); deprecated;
    destructor Destroy(); override; deprecated;
  end;

implementation

{ TMyClass }

constructor TMyClass.Create(aParam: Integer);
begin
  inherited Create();
end;      //line 25

destructor TMyClass.Destroy();
begin
  inherited Destroy();
end;

end.
program test;

uses
  Unit2;

var
  x: TMyClass;
begin
  x := TMyClass.Create(4);
  x.Free;
end.

Compile with fpc main (or 3.2.2):

C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc test.pas
Free Pascal Compiler version 3.3.1 [2023/08/19] for i386
Copyright (c) 1993-2023 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
Compiling unit2.pp
unit2.pp(25,1) Warning: Symbol "Destroy" is deprecated
test.pas(9,26) Warning: Symbol "Create" is deprecated
Linking test.exe
44 lines compiled, 0.2 sec, 157168 bytes code, 6788 bytes data
2 warning(s) issued

The (25,1) for the warning about destroy seems to make no sense.
(Never mind that it makes little sense to deprecate both the constructor and the destructor of a class.)

First reported in the forum by user Чебурашка.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information