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 :(
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 :(
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.
ReplyDeleteThe 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.
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
ReplyDeletefunction 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;
Not sure what CAN_TEST_VERSION does, but there is an intrinsic define CONDITIONALEXPRESSIONS probably suitable for that:
ReplyDeletehttp://docwiki.embarcadero.com/RADStudio/Tokyo/en/Conditional_compilation_(Delphi)#Using_Conditional_Defines_for_the_Compiler_Version
BTW, H2077 is a hint - but it should have been a warning, IMO.
ReplyDeletePaul TOTH same code?
ReplyDeleteHallvard 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).
ReplyDeletea 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
Paul TOTH It was just that your sample code above have the exact same code in the two IFDEF branches.
ReplyDeleteYou 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.
Hallvard Vassbotn you haven't read my code well, for a CompilerVersion >= 32 the code is ignored and there's no H2077.
ReplyDeleteThere'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;