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!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: GNAT bug with assertions Date: Fri, 10 Aug 2018 17:16:13 +0100 Organization: A noiseless patient Spider Message-ID: References: <87y3dejlq9.fsf@adaheads.home> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="bc4d137d7dfc00b04ac666a40b6ff046"; logging-data="5720"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qv3WN0TFHpcs2ZaeZn+at7Q9Pkva7gb8=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (darwin) Cancel-Lock: sha1:jdrx4p3DPs+DugnCRFCNGUX4kBs= sha1:lXghxkFavUtpRM03q45IG3tYb3g= Xref: reader02.eternal-september.org comp.lang.ada:54128 Date: 2018-08-10T17:16:13+01:00 List-Id: Jacob Sparre Andersen writes: > AdaMagica wrote: > >> I would have expected that predicates are also checked on return >> values as they are checked on parameters. In the following test, no >> exception is raised on call of funcction Wrong although it returns a >> value not fulfilling the predicate. >> >> Is this a GNAT bug or my wrong expectation? > > It seems that your expectations are slightly off. Or perhaps you, Jacob, have a later release of the compiler which has this bug fixed? > Contracts are only checked if the assertion policy is set to "Check". > You can do that, either by configuring your compiler to have the > assertion policy set to "Check", or by explicitly inserting: > > pragma Assertion_Policy (Check); > > at the beginning of the units, which should have this assertion policy. Or, in the case of GNAT, by giving -gnata: see http://docs.adacore.com/gnat_ugn-docs/html/gnat_ugn/gnat_ugn/building_executable_programs_with_gnat.html#debugging-and-assertion-control If Cristoph hadn't been using -gnata, the first check would have failed. IMO this is a bug in GNAT, present in CE2018 and FSF GCC 8 (and maybe earlier, didn't check).