Version 1.1 of acs/ac-00289.txt
!standard 4.9(33/3) 17-04-06 AC95-00289/00
!standard 4.9(34/3)
!standard 4.9(35/3)
!class confirmation 17-04-06
!status received no action 17-04-06
!status received 17-04-03
!subject Legality of static attributes
!summary
!appendix
From: Randy Brukardt
Sent: Monday, April 3, 2017 6:47 PM
An ACATS test recently issued contains:
type Unsigned_DWord_Type is mod
Natural'Min (2**32, System.Max_Binary_Modulus);
The expression is needed so that we're not trying to declare a modular type
bigger than the maximum for the implementation.
I compiled this test with two compilers (GNAT, Janus/Ada) and both had no
objections to the code.
Today, an implementer complains that the above expression is illegal on
compilers that have a 16-bit or 32-bit declaration for Integer (which would be
virtually all of them). The expression is fully static, so clearly the
expression is evaluated exactly.
However, one could imagine that 4.9(34/3) applies to the arguments of this
expression:
* The expression is illegal if its evaluation fails a language-defined check
other than Overflow_Check.
Since the operations would be converted to subtype Natural'Base. Such a
conversion would invoke a Range_Check if and only if Natural'Base is
constrained. (4.6(51/4) says a check is performed only if the subtype is
constrained.)
According to 3.5(15), S'Base denotes an unconstrained subtype. So no check is
needed for these arguments, and this 4.9(34/3) does not apply.
Since the expected type of the static expression is "any integer type", the
first part of 4.9(35/2) does not apply either, and "the value may be arbitrarily
large or small".
Therefore, the behavior of GNAT and Janus/Ada on this snippet is correct, if my
analysis is correct.
Agree? Disagree? Don't care? :-)
***************************************************************
From: Tucker Taft
Sent: Tuesday, April 4, 2017 1:37 AM
I agree with your analysis. I am curious why the implementer felt it was
illegal. Did they cite an RM paragraph identifying the reason?
***************************************************************
From: Randy Brukardt
Sent: Tuesday, April 4, 2017 1:55 AM
> I agree with your analysis. I am curious why the implementer felt it
> was illegal. Did they cite an RM paragraph identifying the reason?
Not in those words:
"The type declaration Unsigned_DWord_Type in the new test C453001 is only valid
when Natural'Last >= 2**32 (since the arguments to Natural'Min must belong to
Natural's base type, i.e. Integer)."
The parenthetical remark seems to refer to 4.9(35/2), but that clearly only
applies to the entire static expression and not to the individual operands. I've
sent a reply with the analysis and we'll see if they object. I don't see
anything significant that has changed since Ada 95. Without the BI AI95-0269-1
4.9(35) was just nonsense in the "any integer type" case but the complaint
doesn't seem to be about that - since he refers to "arguments" and the
problematic case would be for the entire expression. (And the AI just makes
explicit what one would expect from the Dewar rule anyway.)
***************************************************************
From: Bob Duff
Sent: Tuesday, April 4, 2017 5:43 AM
> "The type declaration Unsigned_DWord_Type in the new test C453001 is
> only valid when Natural'Last >= 2**32 (since the arguments to
> Natural'Min must belong to Natural's base type, i.e. Integer)."
But that base type has an infinite set of values.
There's no requirement that it be in the base range.
(Confusing!)
I agree with Randy and Tucker.
***************************************************************
Questions? Ask the ACAA Technical Agent