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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: working with diferent instances of the same generic interface Date: Tue, 8 Sep 2015 19:11:38 +0200 Organization: A noiseless patient Spider Message-ID: References: <625c79d2-f5ed-4cd4-80ea-ea310e381017@googlegroups.com> Reply-To: nonlegitur@futureapps.de Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 8 Sep 2015 17:09:47 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="b96887e80893c84a90c3007226ca0d1c"; logging-data="32238"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CznB8d+UDrqkgRw6MsuBiiJXLUqVU1jY=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 In-Reply-To: <625c79d2-f5ed-4cd4-80ea-ea310e381017@googlegroups.com> Cancel-Lock: sha1:87veXTZccPZmZdL286RC5ljHgCQ= Xref: news.eternal-september.org comp.lang.ada:27745 Date: 2015-09-08T19:11:38+02:00 List-Id: On 08.09.15 17:10, Aitor Alcrudo Sangros wrote: > procedure try is > man :manager ; > elm1 : Element_type_A_Access ; > elm2 : Element_type_B_Access ; > begin > man.add(Reporter.Reporting_basic.Reporting_Element_Access(elm1) ); > man.add(Reporter.Reporting_basic.Reporting_Element_Access(elm2) ); > end; > > This compiles, but produces a runtime exception with invalid interface conversion. > > Is there any way to get this to work?. Not sure, after skimming. (It looks like a C++ design written using Ada syntax, although there is a formal tagged type in the first template's parameters ;-) I think the problem may be one of trying to convert half-a-bee into half-a-frog. That's in try's block of statements, where the other half would be Reporting_Element. But, by the above remark, I'm not sure. Simplifying, I can get GNAT in trouble using this program, trying to expose what I think the conversion of elm1 and elm2 amounts to: procedure Test_Tp is package Tp is type X is interface; type A is tagged null record; type B is tagged null record; type C is new A and X with null record; type D is new B and X with null record; end Tp; use Tp; type X_Ptr is access all X'Class; Item : X_Ptr := new D; Z : X'Class := X(Item.all); -- <-- Here begin null; end Test_Tp; The running program show memory access failures on some platforms, referring to the line marked "<-- Here". Starting gdb, after compiling the library with the program, I see Program received signal SIGSEGV, Segmentation fault. 0x000000000040e017 in ada.tags.displace (this=(system.address) 0x7fffffffd408, t=0x7fffffffdf48 (test_tp.tp.x)) at /home/bauhaus/opt/GNAT2014/lib/gcc/x86_64-pc-linux-gnu/4.7.4/adainclude/a-tags.adb:375 375 Obj_DT_Tag := To_Tag_Ptr (Obj_Base).all; So, one might conclude that to much multiple inheritance is involved...