comp.lang.ada
 help / color / mirror / Atom feed
* Wrong GNAT warning. How to suppress it?
@ 2017-11-25 18:03 Victor Porton
  2017-11-25 18:09 ` Pascal Obry
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Victor Porton @ 2017-11-25 18:03 UTC (permalink / raw)


How to eliminate the GNAT warning in the below program?

$ gcc-7 -c main.adb
main.adb:13:05: warning: "return" statement missing following this statement
main.adb:13:05: warning: Program_Error may be raised at run time


procedure Main is

  procedure My_Raise is
  begin
    raise Constraint_Error;
  end;

  function F (I: Integer) return Integer is
  begin
    if I = 0 then
      return 1;
    end if;
    My_Raise;
  end;

begin
  null;
end;

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Wrong GNAT warning. How to suppress it?
  2017-11-25 18:03 Wrong GNAT warning. How to suppress it? Victor Porton
@ 2017-11-25 18:09 ` Pascal Obry
  2017-11-25 18:27 ` Victor Porton
  2017-11-26 19:31 ` Robert Eachus
  2 siblings, 0 replies; 5+ messages in thread
From: Pascal Obry @ 2017-11-25 18:09 UTC (permalink / raw)


Le samedi 25 novembre 2017 à 20:03 +0200, Victor Porton a écrit :
> How to eliminate the GNAT warning in the below program?
> 
> $ gcc-7 -c main.adb
> main.adb:13:05: warning: "return" statement missing following this
> statement
> main.adb:13:05: warning: Program_Error may be raised at run time
> 
> 
> procedure Main is
> 
>   procedure My_Raise is

  procedure My_Raise with No_Return is
  begin
    raise Constraint_Error;
  end;

-- 
  Pascal Obry /  Magny Les Hameaux (78)

  The best way to travel is by means of imagination

  http://www.obry.net

  gpg --keyserver keys.gnupg.net --recv-key F949BD3B


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Wrong GNAT warning. How to suppress it?
  2017-11-25 18:03 Wrong GNAT warning. How to suppress it? Victor Porton
  2017-11-25 18:09 ` Pascal Obry
@ 2017-11-25 18:27 ` Victor Porton
  2017-11-25 19:03   ` Pascal Obry
  2017-11-26 19:31 ` Robert Eachus
  2 siblings, 1 reply; 5+ messages in thread
From: Victor Porton @ 2017-11-25 18:27 UTC (permalink / raw)


Victor Porton wrote:

> How to eliminate the GNAT warning in the below program?
> 
> $ gcc-7 -c main.adb
> main.adb:13:05: warning: "return" statement missing following this
> statement main.adb:13:05: warning: Program_Error may be raised at run time
> 
> 
> procedure Main is
> 
>   procedure My_Raise is
>   begin
>     raise Constraint_Error;
>   end;
> 
>   function F (I: Integer) return Integer is
>   begin
>     if I = 0 then
>       return 1;
>     end if;
>     My_Raise;
>   end;
> 
> begin
>   null;
> end;

The issue was solved by adding pragma No_Return to My_Raise procedure.

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Wrong GNAT warning. How to suppress it?
  2017-11-25 18:27 ` Victor Porton
@ 2017-11-25 19:03   ` Pascal Obry
  0 siblings, 0 replies; 5+ messages in thread
From: Pascal Obry @ 2017-11-25 19:03 UTC (permalink / raw)


Le samedi 25 novembre 2017 à 20:27 +0200, Victor Porton a écrit :
> The issue was solved by adding pragma No_Return to My_Raise
> procedure.

20 minutes after my reply :)

-- 
  Pascal Obry /  Magny Les Hameaux (78)

  The best way to travel is by means of imagination

  http://www.obry.net

  gpg --keyserver keys.gnupg.net --recv-key F949BD3B

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Wrong GNAT warning. How to suppress it?
  2017-11-25 18:03 Wrong GNAT warning. How to suppress it? Victor Porton
  2017-11-25 18:09 ` Pascal Obry
  2017-11-25 18:27 ` Victor Porton
@ 2017-11-26 19:31 ` Robert Eachus
  2 siblings, 0 replies; 5+ messages in thread
From: Robert Eachus @ 2017-11-26 19:31 UTC (permalink / raw)


On Saturday, November 25, 2017 at 1:03:24 PM UTC-5, Victor Porton wrote:
> How to eliminate the GNAT warning in the below program?

For the record, pragma No_Return is deprecated (J.15.2) in favor of aspect No_Return:
  procedure Fatal_Error(M: Message);
    with No_Return;

That allows the compiler to optimize the calling side, for example by not saving register values.

But keep in mind that when GNAT warns you about a function with a path that does not lead to a return statement or raise statement, it is warning about an error that can occur at run-time.  Yes, you will get Program_Error raised, but sometimes that will unexpectedly be handled by a when others handler.

What I do is have a package:

package To_Be_Done is
  procedure TBD(Which: Integer := 0);
    with No_Return;
  function TBD(Which: Integer := 0) return Integer;
  -- and a few other cases
end To_Be_Done;

One advantage of this is that you never check in To_Be_Done for the release (not debug) version.  Can you 'ship' with TBDs?  Of course, but if you intend to do that, you want a version of the To_Be_Done package which is customer friendly, and doesn't splat debug info all over the screen.

The value Which if passed is expected to be the number in the bug list for this particular case.  I'd like to use aspect No_Return for the functions, but, for whatever reason it is limited to procedures and generic procedures.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-26 19:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-25 18:03 Wrong GNAT warning. How to suppress it? Victor Porton
2017-11-25 18:09 ` Pascal Obry
2017-11-25 18:27 ` Victor Porton
2017-11-25 19:03   ` Pascal Obry
2017-11-26 19:31 ` Robert Eachus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox