comp.lang.ada
 help / color / mirror / Atom feed
* Derivation, discriminants, and views.
@ 1999-07-12  0:00 Stanley R. Allen
  1999-07-14  0:00 ` Tucker Taft
  0 siblings, 1 reply; 2+ messages in thread
From: Stanley R. Allen @ 1999-07-12  0:00 UTC (permalink / raw)



Language lawyers and philosophers:

The packages Pack2 and Pack2.Child given below are treated differently
by two Ada 95 compilers.  I am unsure about which one is correct.  From
the partial view, type Basic is unconstrained.  The full view of Basic
is constrained.  The spec of Pack2.Child derives a new type from Basic
in the partial view (visible part) and adds a discriminant.  This seems
like it should be illegal according to RM95 3.7(13) -- and that is
the interpretation of the compiler I am calling COMPILER A.  COMPILER B
has a different interpretation; see the comments in the spec of package
Pack2.Child.

So, I have three questions: which compiler is correct?  If COMPILER B
is correct, which rules make it so?  And if COMPILER B is correct,
doesn't this represent a language anomoly, because the 'clients' of
package heirarchy Pack2 'see' a violation of RM95 3.7(13)?

Stanley Allen
mailto:s_allen@hso.link.com

------------------------------------------------------------
package Pack2 is

    type Basic (<>) is abstract tagged limited private;

    procedure Increment (B : in out Basic'Class);

    procedure Operation (B : in out Basic) is abstract;

private

    type Basic is abstract tagged limited
        record
            Item : Integer;
        end record;

end Pack2;

package body Pack2 is

    procedure Increment (B : in out Basic'Class) is
    begin
        B.Item := B.Item + 1;
    end Increment;

end Pack2;

package Pack2.Child is

    type Fancy (N : access Integer) is new Basic with private;
-------------------------------------------^
--  Fancy is derived from an unconstrained type, in this view
--
--  COMPILER A complains, referencing RM95 3.7(13)
--  COMPILER B accepts, here is a comment from vendor B:
--
--  "COMPILER B is correct here, the declaration of derived type Fancy
--  in your example is legal.  The full type is derived from a
--  constrained view of the parent type and doesn't violate the
--  stated rule."
--
--  COMPILER B reports an error if Fancy is not a private type, but is
--  declared instead as this:
--
--  type Fancy (N : access Integer) is new Basic with null record;
--

    type Fancy_Ptr is access all Fancy'Class;

    function New_Fancy (Init : access Integer) return Fancy_Ptr;

    procedure Operation (F : in out Fancy);   -- override

private

    type Fancy (N : access Integer) is new Basic with null record;
-------------------------------------------^
--  Fancy is derived from a constrained type, in this view
--

end Pack2.Child;

package body Pack2.Child is

    function New_Fancy (Init : access Integer) return Fancy_Ptr is
        Temp : Fancy_Ptr;
    begin
        Temp := new Fancy (N => Init);
        Basic (Temp.all).Item := Init.all;
        return Temp;
    end New_Fancy;

    procedure Operation (F : in out Fancy) is
    begin
        null;
    end Operation;

end Pack2.Child;
---------------------------------------------------------------




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

end of thread, other threads:[~1999-07-14  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-12  0:00 Derivation, discriminants, and views Stanley R. Allen
1999-07-14  0:00 ` Tucker Taft

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