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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Problem with Position of the enumeration Type Date: Wed, 23 Jan 2019 20:34:55 -0800 Organization: None to speak of Message-ID: References: <3d782720-227d-4d86-b403-eacbd1b9d0d2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="408bb0283150d2fd02799035b8169951"; logging-data="28686"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19N60Vd6FO9s6mgPhBcDCSK" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:TeIHIBs/1Fn1ClL9ySrdd0wn/IY= sha1:+NQB4VGTfT50nHYDhcc+3lDOY5M= Xref: reader01.eternal-september.org comp.lang.ada:55354 Date: 2019-01-23T20:34:55-08:00 List-Id: Keith Thompson writes: > "Randy Brukardt" writes: >> "Simon Wright" wrote in message >> news:lyzhrruww2.fsf@pushface.org... >> ... >>> As Karl Müller hinted, you can use the non-standard GNAT >>> implementation-defined attribute 'Enum_Rep[1]. The next page describes >>> 'Enum_Val. >> >> It's Standard, just not until Ada 2020. See >> http://www.ada-auth.org/standards/2xrm/html/RM-13-4.html#p10.1. >> >> (Yes, borrowed from GNAT.) > > I'm glad to see this being standardized. GNAT 7.30 has a bug in its implementation of the 'Enum_Val attribute. In some cases, it appears to examine only the low-order bits of the argument, causing it to yield a valid value when it should raise Constraint_Error. A demo: with Ada.Text_IO; use Ada.Text_IO; procedure Enum_Bug is type Enum is (Two, Four); for Enum use (2, 4); begin for I in 10 .. 11 loop begin Put(Integer'Image(I) & ": "); Put_Line(Enum'Image(Enum'Enum_Val(I))); exception when Constraint_Error => Put_Line("Constraint_Error"); end; end loop; end Enum_Bug; Expected output: 10: Constraint_Error 11: Constraint_Error Actual output: 10: TWO 11: Constraint_Error I'll also report this via https://www.adacore.com/community/contact -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */