Re: GNAT won't link on "warning"

From: David C. Hoos, Sr. (david.c.hoos.sr_at_ada95.com)
Date: 11/29/04


Date: Mon, 29 Nov 2004 06:37:38 -0600
To: <martin@krischik.com>

The reason it won't compile is that you caused the constraint
error at compile time. This is an error and not a warning.

When runtime constraint errors are detected at compile time,
the warning message says "will raise constraint_error." The
message you received said "raises constraint_error," i.e.
present tense, instead of the future tense warning.

If you do the illegal conversion at run time (i.e. after
the "begin," it will compile and link, with a warning, but
fail at run time.

----- Original Message -----
From: "Martin Krischik" <martin@krischik.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: November 29, 2004 3:45 AM
Subject: GNAT won't link on "warning"

> Hello,
>
> For demonstation purpose I wanted to write a program which will raise an
> exception on converting some data:
>
> with Ada.Text_IO;
>
> procedure Convert_Checked
> is
> type Short_Short_Integer is range -(2**7) .. +(2**7-1);
> type Byte is mod 2**8;
>
> package T_IO renames Ada.Text_IO;
> package M_IO is new Ada.Text_IO.Modular_IO (Byte);
>
> A : constant Short_Short_Integer := -1;
> B : constant Byte := Byte (A);
> begin
> T_IO.Put ("B = ");
> M_IO.Put (
> Item => B,
> Width => 5,
> Base => 10);
> end Convert_Checked;
>
> When I compile the demo I get:
>
> convert_checked.adb:12:40: value not in range of type "Byte" defined at line
> 6
> convert_checked.adb:12:40: static expression raises "Constraint_Error"
>
> It is my intention to use a value which is not in range of type "Byte" and
> "Constraint_Error" is precicly what I want to demonstate.
>
> However, GNAT won't link the program. Actually GNAT won't even create an *.o
> file. Is this right? Is there an option to force creation?
>
> With Regards
>
> Martin
>
> --
> mailto://krischik@users.sourceforge.net
> http://www.ada.krischik.com
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
>



Relevant Pages

  • Re: VB Compiler Warnings & other woes ...
    ... you will get this warning in vs 2005. ... > have a direct legacy language path of evolution to consider. ... >> compile time errors rather than runtime. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: g++ compile warning: extra tokens at end of #include directive
    ... > instead of having the class definition in the main file. ... > getting this warning at compile time: ... The definitions are in "myclass.cpp" and get added to your compile ...
    (comp.lang.cpp)
  • Re: [coding practises] do you declare your superclass "throws"??
    ... It could stand to give a warning in this case, or where it's final or private. ... and then having to also comment out the try-catch. ... Java's philosophy tends to be to check as much as can be checked at compile time. ...
    (comp.lang.java.programmer)
  • Re: Annoying 1.5 warnings
    ... To understand the warning, you need to understand how generics work. ... While at compile time generic types are full, ...
    (comp.lang.java.programmer)
  • Re: GNAT wont link on "warning"
    ... This is an error and not a warning. ... > When runtime constraint errors are detected at compile time, ... instead of the future tense warning. ...
    (comp.lang.ada)