> Am 01.10.2025 um 12:46 schrieb Martin Frb via fpc-devel 
> <[email protected]>:
> 
> In the code
> 
>   if true then begin
>     write(1);
>   end
>   else begin
>     write(2);
>   end;
> 
> the "else" block will not generate code (at least O2 and higher).
> 
> But
> 
>   TFoo = class
>     procedure MyFoo;
>   end;
>   X = class(TFoo)
>   end;
> 
> 
>   //if @X.MyFoo = @TFoo.MyFoo then begin
>   if @TFoo.MyFoo = @TFoo.MyFoo then begin
>     write(1);
>   end
>   else begin
>     write(2);
>   end;
> 
> Does not detect this at compile time.
> 
> Note, that this is not on an instance, this is on the actual class => so it 
> is known.
> 
> Is there any way to get that optimize the "else" block away (or the "then" if 
> the compare goes the other way)?
> I can't just compare the classes, as subclasses can have the same method (if 
> it isn't overridden/reintroduced)

I added an optimization for this in dbf7ba4721f8336139e84a99c74b89025edc55c3. 
Can you please check if it works for your case?

_______________________________________________
fpc-devel maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to