Skip to content

Ambiguous overloaded functions might crash the compiler instead of printing an error, probably if there is no current_procinfo. :)

Forcibly overloading intrinsics this way might not be the wisest thing to do (this issue was closed with a “won’t do”), but there might be better examples...

This code, as a part of a unit (as opposed to the main program; probably to ensure current_procinfo = nil 😄), crashes the compiler at ncal.pas:3826.

{$mode objfpc}
unit SomeUnit;

interface

	function Bsr(const value: byte): byte; internproc: fpc_in_bsr_x;
	function Bsr(const value: word): cardinal; internproc: fpc_in_bsr_x;
	function Bsr(const value: dword): cardinal; internproc: fpc_in_bsr_x;
{$ifdef cpu64}
	function Bsr(const value: qword): cardinal; internproc: fpc_in_bsr_x;
{$endif}

type
	SomeEnum = (A, B, C, D);

const
	SomeEnumBits = 1 + Bsr(ord(High(SomeEnum)) or 1);

implementation

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