Codebot.Cross icon indicating copy to clipboard operation
Codebot.Cross copied to clipboard

Compiler bug in gdiplus.pas

Open EganSolo opened this issue 4 years ago • 1 comments

Lazarus 2.0.12 FPC 3.2.0 SVN Revision: 64642. Downloaded the zip file code.codebot-master loaded the package codebot and hit compile. Compilation error in gdiplus.pas, line 11906: Can't determine which overloaded function to call. Function in question is TGdiBitmap.create(size * 2, Size * 2) This is really weird. I checked all the constructors you have in this class:

  {01}  constructor Create(Bitmap                       : GpBitmap                                                                                ); overload;
  {02}  constructor Create(Filename                    : WideString; UseEmbeddedColorManagement: Boolean = False); overload;
  {03}  constructor Create(Stream                      : IStream      ; UseEmbeddedColorManagement: Boolean = False); overload;
  {04}  constructor Create(Width, Height, Stride : Integer       ; Format                                       : TPixelFormat     ;
                                        scan0                        : PByte                                                                                       ); overload;
  {05}  constructor Create(Width, Height            : Integer      ; Format: TPixelFormat = PixelFormat32bppArgb     ); overload;
  {06}  constructor Create(Width, Height            : Integer      ; Target : IGdiGraphics                                             ); overload;
  {07}  constructor Create(surface                       : IDirectDrawSurface7                                                                ); overload;
  {08}  constructor Create(var BitmapInfo           : TBitmapInfo; BitmapData                                : Pointer            ); overload;
  {09}  constructor Create(Bmp                          : HBitmap      ; Pal                                             : HPALETTE        ); overload;
  {10}  constructor Create(Icon                          : HICON                                                                                     ); overload;
  {11}  constructor Create(hInstance                 : HMODULE  ; BitmapName                               : WideString      ); overload;

It seems to me that the call at line 11906 is calling constructor number 5 which has a signature that is different from the signatures of the other constructors. Further, the superclass TGDImage does not have a constructor that could clash with constructor number 5. The same holds true for TInterfacedObjet and TObject.

Could that be a bug in the compiler?

EganSolo avatar Mar 29 '21 00:03 EganSolo

I'm on Win64 and the compiler is getting confused between declarations 5 and 9 because you're making a call that's passing 2 * Size, and that could be interpreted as a Qword if 2 * size overflows the integer bounds.

Solution: If you're certain that 2 * Size will always be less than MaxInt, then either typecast 2 * Size to integer when passing it or assign it to an integer variable before making the call.

EganSolo avatar Mar 29 '21 09:03 EganSolo