Can we please get the compiler generate W1035 (Return value of function might be undefined) for managed data types also?

Can we please get the compiler generate W1035 (Return value of function might be undefined) for managed data types also?

While I understand why this is not happening atm (internal handling of Result as var/out parameter) it would be very useful and prevent errors.

Code like this would show an error and avoid wrong data:

function Foo(list: TStringList): string;
var
  s: string;
begin
  for s in list do
    Result := Result + s;
end;

Currently it does not show any warning and might have an unexpected result depending on what was inside the variable the function result is assigned to.

Comments

  1. Even better have compiler generate a known initial value.

    ReplyDelete
  2. Better for the compiler to complain on using non-initialed variable.

    ReplyDelete
  3. Russell Peters I checked what the compiler does when you write:

    function Foo: Integer;
    begin
      Result := Result + 42;
    end;

    and it is the W1035 and not W1036.

    ReplyDelete

Post a Comment