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!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: =?windows-1252?Q?Markus_Sch=F6pflin?= Newsgroups: comp.lang.ada Subject: Re: Unexpected discriminant check failure involving access types Date: Mon, 10 Aug 2015 16:20:36 +0200 Organization: Aioe.org NNTP Server Message-ID: <55C8B334.2010102@spam.spam> References: NNTP-Posting-Host: MdpKeRr+sx3LK7JQiK5aNw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:27404 Date: 2015-08-10T16:20:36+02:00 List-Id: Am 10.08.2015 um 15:14 schrieb Mark Lorenzen: > On Monday, August 10, 2015 at 2:38:23 PM UTC+2, Markus Schöpflin wrote: >> Given the following piece of code: >> >> ---%<--- >> 1 procedure TEST >> 2 is >> 3 type T is (T1, T2); >> 4 >> 5 type RECORD_T (X : T := T1) is record >> 6 null; >> 7 end record; >> 8 >> 9 type PTR_T is access RECORD_T; >> 10 >> 11 FOO : RECORD_T; >> 12 FOO_PTR : constant PTR_T := new RECORD_T; >> 13 >> 14 FOO1 : constant RECORD_T := (X => T1); >> 15 FOO2 : constant RECORD_T := (X => T2); >> 16 begin >> 17 FOO := FOO1; >> 18 FOO := FOO2; >> 19 >> 20 FOO_PTR.all := FOO1; >> 21 FOO_PTR.all := FOO2; >> 22 end; >> --->%--- >> >> When compiled and executed, I get: >> >> > ./test >> >> raised CONSTRAINT_ERROR : test.adb:21 discriminant check failed >> >> Can anyone please explain me why I get a discriminant check error when using >> access types? I would have expected it to work the same as for the non-access >> case. >> >> TIA, Markus > > Look at line 12. FOO_PTR is a constant object of an access type. The > constant object is initialized to point to a discriminated record with > discriminant T1, since this is the default discriminant of objects of type > RECORD_T. In line 21 it goes horribly wrong and you try to change the > object pointed to, to a record with discriminant T2. I still don't get it: I would have expected the objects FOO and FOO_PTR.all to be identical in behaviour. Why is "new RECORD_T" creating a constrained record and just using "RECORD_T" not? > What problem are you trying to solve? Is the above code just a simple > reproducer or is it a snippet from real code? That is a reproducer for a bug found in some real code, which suddenly started to give constraint errors, due to a change in the initialization of a variable of type PTR_T. Markus