comp.lang.ada
 help / color / mirror / Atom feed
* Ada.Calendar.Formatting bug in GNAT?
@ 2011-09-16 19:55 Maciej Sobczak
  2011-09-17  5:59 ` Randy Brukardt
  0 siblings, 1 reply; 2+ messages in thread
From: Maciej Sobczak @ 2011-09-16 19:55 UTC (permalink / raw)


I have a problem with Ada.Calendar.Formatting.Image with the Duration
parameter.

As far as I understand 9.6.1, points 86.a/2:

"Implementation defined: The result of Calendar.Formating.Image if its
argument represents more than 100 hours."

and 86.b/2:

"Implementation Note: This cannot be implemented (directly) by calling
Calendar.Formatting.Split, since it may be out of the range of
Day_Duration, and thus the number of hours may be out of the range of
Hour_Number."

the Image function should cope with Durations longer than one day (but
not longer than 100 hours) and Day_Duration should not be a limitation
here.

Let's try:

with Ada.Calendar.Formatting;
with Ada.Text_IO;

procedure Test is

   Hour : constant Duration := 3_600.0;

   D_1 : constant Duration := 23 * Hour;
   D_2 : constant Duration := 25 * Hour;

begin
   Ada.Text_IO.Put_Line (Ada.Calendar.Formatting.Image (D_1));
   Ada.Text_IO.Put_Line (Ada.Calendar.Formatting.Image (D_2));
end Test;

$ ./test
23:00:00

raised CONSTRAINT_ERROR : a-calfor.adb:381 explicit raise
$

The a-calfor.adb:381 is a raise statement in:

      if not Seconds'Valid then
         raise Constraint_Error;
      end if;

where Seconds is of type Day_Duration in function Split. Yes, the same
Split which should not be used according to AARM.

Is this a bug in the GNAT library? I think so.

I have an additional question, though: why the constraints of
Day_Duration were not detected at the point of call to Split, but
rather later on with explicit test on Seconds'Valid? My understanding
is that this should be checked at the point of call to Split, so that
additional checks inside Split should not be necessary. A possible
explanation is that the library was compiled with checks disabled and
the explicit test was added to cover up for this, but maybe I'm
missing something here.

--
Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com



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

* Re: Ada.Calendar.Formatting bug in GNAT?
  2011-09-16 19:55 Ada.Calendar.Formatting bug in GNAT? Maciej Sobczak
@ 2011-09-17  5:59 ` Randy Brukardt
  0 siblings, 0 replies; 2+ messages in thread
From: Randy Brukardt @ 2011-09-17  5:59 UTC (permalink / raw)


"Maciej Sobczak" <see.my.homepage@gmail.com> wrote in message 
news:e781c174-04fe-4445-9788-c6f619439c5d@l2g2000vbn.googlegroups.com...
...
> I have an additional question, though: why the constraints of
> Day_Duration were not detected at the point of call to Split, but
> rather later on with explicit test on Seconds'Valid? My understanding
> is that this should be checked at the point of call to Split, so that
> additional checks inside Split should not be necessary. A possible
> explanation is that the library was compiled with checks disabled and
> the explicit test was added to cover up for this, but maybe I'm
> missing something here.

My understanding is that the GNAT runtime is always compiled with checks 
turned off, so I presume they write explicit checks whenever they are 
needed. (We do something similar for the Janus/Ada runtime.)

As for the original problem, it surely sounds like a bug.

                         Randy.





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

end of thread, other threads:[~2011-09-17  5:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-16 19:55 Ada.Calendar.Formatting bug in GNAT? Maciej Sobczak
2011-09-17  5:59 ` Randy Brukardt

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