From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: GNAT bug with assertions
Date: Fri, 10 Aug 2018 07:23:34 -0700 (PDT)
Date: 2018-08-10T07:23:34-07:00 [thread overview]
Message-ID: <fab0d2a8-098f-46bc-9728-841627ce3177@googlegroups.com> (raw)
In-Reply-To: <a9ceb787-b964-4c53-91de-02bee039f6e5@googlegroups.com>
On Friday, August 10, 2018 at 3:29:34 AM UTC-7, AdaMagica wrote:
> I would have expected that predicates are also checked on return values as they are checked on parameters.
> In the following test, no exception is raised on call of funcction Wrong although it returns a value not fulfilling the predicate.
>
> Is this a GNAT bug or my wrong expectation?
>
> package Pack is
>
> type Priv is private;
> C: constant Priv;
>
> function Test (X: Priv) return Boolean;
> subtype Subt is Priv with Dynamic_Predicate => (Test (Subt));
>
> function Wrong return Subt;
> function Good (X: Subt) return Boolean;
>
> private
>
> type Priv is new Integer;
> C: constant Priv := -1;
>
> function Test (X: Priv) return Boolean is (X > 0);
>
> function Wrong return Subt is (-1);
> function Good (X: Subt) return Boolean is (True);
>
> end Pack;
>
> with Ada.Assertions, Ada.Text_IO;
> use Ada.Assertions, Ada.Text_IO;
>
> with Pack;
> use Pack;
>
> procedure Test_Pack is
> begin
>
> begin
> Put_Line (Good (C)'Image);
> exception
> when Assertion_Error =>
> Put_Line ("Good (C) raises Assertion_Error => OK");
> end;
>
> declare
> X: Priv;
> begin
> X := Wrong;
> Put_Line ("Assertion_Error expected by calling Wrong => KO");
> exception
> when Assertion_Error =>
> Put_Line ("Wrong raises Assertion_Error => OK");
> end;
>
> end Test_Pack;
I assume you used -gnata switch for your GNAT compilation. Otherwise, you will not see the effect.
Anh Vo
next prev parent reply other threads:[~2018-08-10 14:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-10 10:29 GNAT bug with assertions AdaMagica
2018-08-10 14:23 ` Anh Vo [this message]
2018-08-10 15:16 ` Jacob Sparre Andersen
2018-08-10 16:16 ` Simon Wright
2018-08-10 20:42 ` Randy Brukardt
2018-08-12 18:35 ` AdaMagica
2018-08-12 18:51 ` Simon Wright
2018-08-13 9:03 ` AdaMagica
2018-08-13 9:07 ` Simon Wright
2018-08-13 15:54 ` Simon Wright
2018-08-13 16:55 ` Simon Wright
2018-08-14 2:37 ` AdaMagica
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox