comp.lang.ada
 help / color / mirror / Atom feed
From: sbelmont700@gmail.com
Subject: Re: Type extension and discriminants
Date: Sat, 11 Oct 2014 10:45:55 -0700 (PDT)
Date: 2014-10-11T10:45:55-07:00	[thread overview]
Message-ID: <aa0678d5-f777-4a52-952f-dc9a2f16ed74@googlegroups.com> (raw)
In-Reply-To: <m19muc$551$1@loke.gir.dk>

On Friday, October 10, 2014 6:34:54 PM UTC-4, Randy Brukardt wrote:
> It would have helped a bit had you given an example.

Thank you for your response.  An example follows:

package A is
   type T1 (<>) is tagged limited private;
   function T1_Ctor return T1;
private
   type T1 (I_Ptr : access Integer) is tagged limited null record;
end A;


package body A is
   function T1_Ctor return T1 is
   begin
      return (I_Ptr => null);
   end T1_Ctor;
end A;


with A;
package B is
   type T2 (<>) is new A.T1 with private;
   function T2_Ctor return T2;
private
  type T2 is new A.T1 with null record;
end B;

package body B is
   function T2_Ctor return T2 is
   begin
      return T2'(A.T1_Ctor with null record);
   end T2_Ctor;
  
end B;

This code as written makes GNAT go Blammo when compiling b.adb {GPL 2014 (20140331) (i686-pc-mingw32) GCC error: in gnat_to_gnu_entity, at ada/gcc-interface/decl.c:289 | Error detected at b.ads:11:8}, so clearly there is a bug in there somewhere, but more often than not crashes come from parsing bad code on my end, so I just assume it's me.  Then when playing around I realized that it would accept T2 without the explicit (<>), and was doubtful as to whether it had to be there (I prefer it as well), or if it was just implicitly declared from T1 (like 'limited'), which was followed by my realization that I didn't even know if this should be valid to begin with.

Moreover, changing T1 from an access discriminant (e.g. just 'Integer' instead of 'access Integer'), makes it compile fine, but removing all the discriminants from T1 (but leaving it unknown in the public part) causes an odd compiler error (uninitialized unconstrained allocation not allowed / qualified expression required) on the full type declaration of T2, which seems like at least the wrong error message, if not an error itself (it would seem just as legal to have no discriminants as access or named ones).

Making T1 fully public fixes everything.

The stated approach seems legal, at least in concept, but the variety of crashes and errors made me suspect.  I will be submitting this as a bug report at the very least for the hard crash, and probably for the error messages as well.

Thank you again for your continued helpful responses.

-sb




  reply	other threads:[~2014-10-11 17:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10 20:55 Type extension and discriminants sbelmont700
2014-10-10 22:34 ` Randy Brukardt
2014-10-11 17:45   ` sbelmont700 [this message]
2014-10-11 18:44     ` Simon Wright
2014-10-11 18:52     ` Dmitry A. Kazakov
2014-10-11 21:09       ` sbelmont700
2014-10-12  6:51         ` Dmitry A. Kazakov
2014-10-12 16:27     ` 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