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!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: A function that cannot be called? Date: Sun, 21 Oct 2018 12:14:03 +0200 Organization: A noiseless patient Spider Message-ID: References: <99f41210-6fe2-4b4d-90ad-21a0ab108f53@googlegroups.com> <39dec2d6-7da5-4421-bb50-e4effd5a1439@googlegroups.com> Reply-To: nonlegitur@notmyhomepage.de Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 21 Oct 2018 10:14:04 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="84d535c74bf77e66f2d335d51b8e2cb7"; logging-data="6139"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1808PrLuRDd/VRyuLH17faBlxtGAZPu4nk=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Cancel-Lock: sha1:1uy7vTyIAs95zaI3dtxhY9ygbDc= In-Reply-To: Content-Language: de-DE Xref: reader02.eternal-september.org comp.lang.ada:54679 Date: 2018-10-21T12:14:03+02:00 List-Id: On 20.10.18 00:06, Jere wrote: > Are you ok with runtime checks? If so, you can create a separate package > for the void type: > > package Voids is > type Void is limited private; > private > type Void is new Ada.Finalization.Limited_Controlled > with null record; > overriding procedure Initialize(Self : in out Void); > end Voids; > package body Voids is > procedure Initialize(Self : in out Void) is > begin > raise Program_Error; > end Initialize; > end Voids; > > Here, if try to create a variable of type Void, it will raise > Program_Error (or you can add a custom exception. Same for if > you call a function that tries to return a Voids.Void variable. I like the idea because the compiler will probably not suppress raising the exception. This is unlike relying on Constraint_Error being raised for 1..0. The not null constraint on a component triggers C_E not matter what, it seems. However, Initialize states the intention directly.