[fpc-devel] Data flow analysis (dfa) and "case ... of"
Denis Kozlov
dezlov at gmail.com
Wed Jun 7 01:04:54 CEST 2017
Juha,
Just to get this straight, I am talking about DFA and your proposal to
remove "uninitialized result" warning when all declared values of a set
have been enumerated in a case statement. I don't have any issues with
range check errors, they were brought up and became part of
conversation. Now, put aside range checks and focus on DFA and case
statements.
Consider the code fragment below. Currently, FCP 3.0.2 with -O3 shows
"uninitialized result" warning for Convert2 and Convert3 functions, but
not for Convert1. I find this perfect as is, and, of course, you can
rightfully disagree.
You suggest that only Convert3 function should raise "uninitialized
result" warning, while Convert1 and Convert2 should not. I find this
less useful, and, again, you can rightfully disagree, but it won't
change the fact that it is still less useful for me (and possibly others).
I won't indulge in any further debate. I voiced my opinion/concern and
will leave it at that. Feel free to ignore it.
----------------------------
type
TConvertType = (ctA, ctB);
function Convert1(Value: TConvertType): Integer;
begin
case Value of
ctA: Result := 1;
ctB: Result := 2;
else Result := 0;
end;
end;
function Convert2(Value: TConvertType): Integer;
begin
case Value of
ctA: Result := 1;
ctB: Result := 2;
end;
end;
function Convert3(Value: TConvertType): Integer;
begin
case Value of
ctA: Result := 1;
end;
end;
----------------------------
On 05/06/2017 22:11, Juha Manninen wrote:
> On Mon, Jun 5, 2017 at 9:37 PM, Denis Kozlov <dezlov at gmail.com> wrote:
>> I just wanted to highlight that these cases as legal and I presume not
>> uncommon, particularly if values are deserialized and typecasted.
> No they are not legal. Why you write this nonsense?
> Values outside the range dictated by the type system are always wrong.
> No excuses, no exceptions.
> For the purposes of DFA the compiler can always assume the values are in range.
>
> - Later: -
>> Complier currently warns (cares) about such execution flows
>> which are triggered by invalid data, and I happen to find it useful :)
> Again nonsense.
> The range check -Cr warns about out-of-range data, yes, but this
> thread is about DFA and not about range checks.
> I feel you hijacked my DFA thread for your own purpose but I don't
> really know what that purpose is.
> Are you saying that typecasts should be forbidden to prevent range errors?
> No, it would not prevent bugs in code.
> Anyway, please start a new thread about range check issues.
>
> Juha
More information about the fpc-devel
mailing list