> 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
Re: [fpc-devel] Constant eval (and dead code removal) - comparing 2 methods for being the same.
Florian Klämpfl via fpc-devel Sat, 18 Oct 2025 01:24:15 -0700
- [fpc-devel] Constant eval (and dead code re... Martin Frb via fpc-devel
- Re: [fpc-devel] Constant eval (and dea... Florian Klämpfl via fpc-devel
- Re: [fpc-devel] Constant eval (and... Martin Frb via fpc-devel
