I have just created a new GUI application, enabled range checking "-Cr" and executed the following:

ShowMessage(IntToStr(Form1.BorderSpacing.GetSpace(TAnchorKind(-1))));

The displayed value is a semi-random integer. No compiler errors or run-time errors.

P.S. Same behaviour for Lazarus 1.6.4 + FPC 3.0.2 and Lazarus 1.4.4 + FPC 2.6.4.

Denis


On 05/06/2017 17:51, Jonas Maebe wrote:
On 05/06/17 18:46, Denis Kozlov wrote:
Result is undefined if caller passes an out of range value.

That would be an error at the time this out-of-range value would be converted to TAnchorKind. If range checking is off there or disabled via an explicit type cast, then the result is undefined by definition. The compiler can and does assume in various cases that a type only holds values valid for that type.

On 05/06/2017 18:07, Juha Manninen wrote:
On Mon, Jun 5, 2017 at 7:46 PM, Denis Kozlov <dez...@gmail.com> wrote:
Result is undefined if caller passes an out of range value.
An example: TControlBorderSpacing.GetSpace(TAnchorKind(-1));
Result is indeed not initialized, so silencing this message may be harmful.
Yes but that is an illegal situation. It is already trapped by range check -Cr.
The compiler can safely assume that such situation does not happen.
Actually the compiler already assumes that in other situations. I
remember a bug years ago in Lazarus, caused by an out of range enum
value. FPC had changed its behavior and the bug got triggered.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to