comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Ada.Calendar.Formatting bug in GNAT?
Date: Fri, 16 Sep 2011 12:55:55 -0700 (PDT)
Date: 2011-09-16T12:55:55-07:00	[thread overview]
Message-ID: <e781c174-04fe-4445-9788-c6f619439c5d@l2g2000vbn.googlegroups.com> (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



             reply	other threads:[~2011-09-16 19:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-16 19:55 Maciej Sobczak [this message]
2011-09-17  5:59 ` Ada.Calendar.Formatting bug in GNAT? Randy Brukardt
replies disabled

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