From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,829936167b39e478,start X-Google-Attributes: gid103376,public From: jhassett@my-dejanews.com Subject: Incompatibility involving universal expressions Date: 1998/10/08 Message-ID: <6vj3sb$k7c$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 399083051 X-Http-Proxy: 1.0 x2.dejanews.com:80 (Squid/1.1.22) for client 192.31.86.35 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Oct 08 19:16:41 1998 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (X11; U; SunOS 5.5.1 sun4m) Date: 1998-10-08T00:00:00+00:00 List-Id: I've run into an apparent Ada 83/Ada 95 incompatibility that surprised me because it seems that it would be rather common, and I haven't seen it documented (e.g., in Bill Taylor's Ada Compatibility Guide). The changes that cause the incompatibility are apparently motivated by a desire to eliminate Beaujolais effects (http://www.adahome.com/FAQ/programming.html#beaujolais). I'm wondering if I've misunderstood the situation, and hoping someone can set me straight if I have. Here is an example: with Text_IO; package P is N : constant := 10; type T is new Text_IO.Count range 2 .. N - 1; end P; This compiles under the Rational VADS Ada 83 compiler, but not under the Green Hills Ada 95 compiler ("Error: line 4 col 39 LRM:8.6(28), Expression has no possible interpretation as an expression of the type Count, Continuing"). Maybe Green Hills (or Rational) and I have both missed something, but here's my understanding of the incompatibility: In Ada 83, there are operators defined for type universal_integer (RM83-4.10), so the expression "N - 1" is a universal expression, yielding a universal_integer value. Both the literal "2" and "N - 1" are implicitly converted (RM83-4.6(15)) to type Text_IO.Count, which is the type required for the range constraint (RM83-3.5(4)). Thus, the declaration of T is valid even though the "-" operator for type Text_IO.Count is not directly visible. In Ada 95, there are no operators defined for universal types (RM95-3.4.1(7)), so the "universal expressions" of Ada 83 become expressions of the corresponding root types, and "N - 1" is interpreted as having type root_integer. The Ada 83 rules about implicit conversion of universal types are replaced by rules allowing a construct to have a universal type when the expected type is covered by the universal type (RM95-8.6(24) and AARM95-8.6(34.b)). But this doesn't allow an expression of a root type to be accepted where a descendant is expected (see AARM95-3.4.1(14a)), so when "N - 1" is interpreted as having type root_integer, it is not acceptable. There are several ways to fix the illegal declaration in Ada 95. One is to make the "-" operator for type Text_IO.Count directly visible, so that "N - 1" can be interpreted as having type Text_IO.Count: with Text_IO; package P is use type Text_IO.Count; N : constant := 10; type T is new Text_IO.Count range 2 .. N - 1; end P; Another fix is to explicitly convert "N - 1": type T is new Text_IO.Count range 2 .. Text_IO.Count(N - 1); The rules for number declarations specifically allow expressions of any numeric type, though the named numbers themselves have universal types, so this is also legal: with Text_IO; package P is N : constant := 10; K : constant := N - 1; type T is new Text_IO.Count range 2 .. K; end P; If I've got all this right, it seems that there would be lots of contexts where Ada 83 universal expressions involving operators become expressions having root types in Ada 95, and are not accepted. Is this as common as I think it is? - Jim Hassett -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum