comp.lang.ada
 help / color / mirror / Atom feed
* Ada 95 case statement incompatibility?
@ 1996-08-27  0:00 Gavin Finnie
  1996-08-27  0:00 ` Michael F Brenner
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Gavin Finnie @ 1996-08-27  0:00 UTC (permalink / raw)




Looking at the differences between Ada 83 and Ada 95, there appears to be an
incompatibility which is not mentioned in Appendix X of the Ada 95 Rationale
nor in the Ada Compatibility Guide (Version 6.0 - is this the latest?)

First recall the rule that if the expression in a case statement is the
name of an object whose subtype is static, the set of choices must cover all
and only the values of the subtype, whereas if the subtype is not static, all
values of the base type must be covered.

Now in Ada 95, the definition of static has been extended to include things
that were not static in Ada 83, for example certain array attributes.
This means that some case statements which are legal in Ada 83 become illegal
in Ada 95.

Consider something like

  type A is array (1..10) of integer;
  subtype S is integer range A'FIRST..A'LAST;  -- static in 95, but not in 83
  x : S;
  ...
  case x is
    when integer'FIRST..3 => ... ;
    when 4..6 => ... ;
    when 7..integer'LAST => ... ;
    -- legal Ada 83 since all values of S'BASE *must* be covered
    -- illegal Ada 95 since S is now static, so only 1 to 10 allowed
  end case;

A similar problem occurs if the expression is a call to a function which
returns a value of a static subtype, since a function call is a name in Ada 95
but not in Ada 83.

In practice, these problems are not likely to occur in many programs since the
usual approach would be to use an 'others' clause to cover values outside the
subtype. However, I am surprised that this issue has not been mentioned in the
Ada 95 documentation.

Gavin Finnie




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

end of thread, other threads:[~1996-08-29  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-27  0:00 Ada 95 case statement incompatibility? Gavin Finnie
1996-08-27  0:00 ` Michael F Brenner
1996-08-28  0:00   ` Robert Dewar
1996-08-28  0:00   ` Norman H. Cohen
1996-08-28  0:00     ` Robert Dewar
1996-08-28  0:00 ` Robert Dewar
1996-08-28  0:00   ` Gavin Finnie
1996-08-29  0:00 ` Robert A Duff

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