Jump to content

Recommended Posts

The following gives a hint in D13: H2077 Value assigned to Test never used:

function Test(Value: Integer): Integer;
begin
  Result := -1;
  if Value > 0 then
    Result := 0
  else
    Assert(False);
end;

Is the hint justified?  What if Assertions are turned off?  Note that in earlier versions you would get a warning if you omit the first line.

Edited by pyscripter

Share this post


Link to post
2 minutes ago, pyscripter said:

The following gives a hint in D13: H2077 Value assigned to Test never used:

Not for me.

4 minutes ago, pyscripter said:

What if Assertions are turned off?

Did you try it with assertions turned off?
 

Share this post


Link to post
2 minutes ago, Dave Nottage said:

Not for me.

It does not produce a hint when you target x86, but it does when you target x64.

Share this post


Link to post
3 minutes ago, pyscripter said:

It does not produce a hint when you target x86, but it does when you target x64.

Still does not for me.

EDIT:

Are you using the 64-bit IDE?

Edited by Dave Nottage

Share this post


Link to post

I made some tests. In all cases Hints are enabled.

 

Targets: Win32/Win64

DEBUG, Assertions on : no hint

DEBUG, Assertions off : no hint

RELEASE, Assertions on : hint

RELEASE, Assertions off : No hint

 

The behavior with RELEASE seems fine, but why is it different with DEBUG?

Share this post


Link to post

Actually I am getting the hint with both Win32/Win64  (32 bit IDE) and a DEBUG configuration that looks like a release configuration. 

 

image.png.a8173dab575e53b40f07cf976f351a02.png

 

The funny thing is that if I remove the offending line and disable assertions, then I get a warning about the undefined result!  You can't win.

Edited by pyscripter

Share this post


Link to post
3 minutes ago, pyscripter said:

Actually I am getting the hint with both Win32/Win64  (32 bit IDE) and a DEBUG configuration.

As I am getting just the opposite, there must be some difference with our tests.

Share this post


Link to post
12 minutes ago, Uwe Raabe said:

The behavior with RELEASE seems fine, but why is it different with DEBUG?

Looks like the Optimization switch (off) kills the hint

  • Like 1

Share this post


Link to post

The following correctly produces the same hint, whilst in some earlier Delphi versions it wrongly produced a hint if the offending statement was omitted.

function Test(Value: Integer): Integer;
begin
  Result := -1;
  if Value > 0 then
    Result := 0
  else
    Abort;
end;

 

Edited by pyscripter

Share this post


Link to post
4 hours ago, pyscripter said:

The following correctly produces the same hint

Did they update Abort() to mark it with the new 'noreturn' attribute?

 

Share this post


Link to post
1 hour ago, Remy Lebeau said:

Did they update Abort() to mark it with the new 'noreturn' attribute?

Indeed.

Share this post


Link to post
22 minutes ago, pyscripter said:

Indeed.

Well, then the hint is valid since the value -1 will never be used.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×