Hello

Hello,

How many times have you a warning H2077 for an unused value on a line with the comment "make compiler happy" ? :D

I spend a lot of time to have 0 warning on my projects...and it's painful when a new version change things like that :(

Comments

  1. Was this after upgrading to Tokyo? I found that the new locations introduced actually were correct, and that the value I set actually was not used.

    The variations are too numerous to show all, but

    try
    if condition
    then Exit(SomeValue); //<-- H2077
    finally
    Result := SomeOtherValue;
    end;

    is one example where it actually is a "catastrophic error".

    H2077 is too important to be ignored. Every case needs to be properly analyzed. It is not about making the compiler happy, but understanding the flaws in your code.

    ReplyDelete
  2. Lars Fosdal if you have a code that have to be compatible with multiple versions (components for instance) you have to add "compiler happy" code and remove it for Tokyo

    function Sample: Integer;
    begin
    {$IFDEF CAN_TEST_VERSION}
    {$if CompilerVersion < 32}
    Result := 0; // make compiler before Tokyo happy
    {$ifend}
    {$ELSE}
    Result := 0; // make old compiler happy
    {$ENDIF}
    ....
    end;

    ReplyDelete
  3. BTW, H2077 is a hint - but it should have been a warning, IMO.

    ReplyDelete
  4. Hallvard Vassbotn I have an XE3 application with 0 warning, 0 hint, 0 error...and 34 hints and 60 warning under Tokyo. Most of the warning are about AnsiString functions deprecated from System.AnsiStrings (adding this unit lead to a compilation error, see RSP-19979).

    a lot of Warning about deprectated TCharacter (with some code that $IFDEF UNICODE to use that instead of "in []" (RSP-13141)

    like this https://github.com/project-jedi/jvcl/blob/c290ad082456a6a53a74e6e71fbc9914ee9e9a8e/jvcl/run/JvEditor.pas#L962

    and then some H2077 like those one (I have an old version of JVCL)

    https://github.com/project-jedi/jvcl/search?utf8=%E2%9C%93&q=IFNDEF+COMPILER25_UP&type=
    github.com - jvcl

    ReplyDelete
  5. Paul TOTH It was just that your sample code above have the exact same code in the two IFDEF branches.

    You still haven’t provided a complete code example that triggers an invalid H2077 warning

    We’re still on XE6, but I’m always interested in compiler feedback that can improve code quality.

    ReplyDelete
  6. Hallvard Vassbotn you haven't read my code well, for a CompilerVersion >= 32 the code is ignored and there's no H2077.

    There's no invalid H2077, there was invalid W1035 that where fixed with the comment "make compiler happy", that's what I'm talking about

    a very simple test:

    function test: Integer;
    begin
    Result := 0; // H2077 under Tokyo !
    try
    raise Exception.Create('W1035 under XE3 if Result is not initialize');
    finally
    end;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    test();
    end;

    ReplyDelete

Post a Comment