[Ada] Pass in Out param with Default_Value aspect

Eric Botcazou ebotcazou@adacore.com
Sat Jan 25 10:35:00 GMT 2014


In most cases, out parameters are not passed in, but there have always
been exceptions, notably access types. Ada 2012 adds a new exception
for parameters of a type with a Default_Value. This patch ensures that
such parameters are copied in.

The following program, compiled with -gnata

     1. procedure DefValOut
     2. is
     3.   type R is range 0 .. 10 with Default_Value => 0;
     4.   procedure Wibble (X : out R)
     5.     with Post => X = 0
     6.   is
     7.   begin
     8.      null;
     9.   end Wibble;
    10.   X : R;
    11. begin
    12.   X := 10;
    13.   Wibble (X);
    14. end DefValOut;

used to generate no output, now it generates:

raised SYSTEM.ASSERTIONS.ASSERT_FAILURE :
failed postcondition from defvalout.adb:5

since the value of 10 gets passed in as the initial value of X
and the postcondition fails.


2014-01-25  Robert Dewar  <dewar@adacore.com>

	* gcc-interface/decl.c (gnat_to_gnu_param): Make sure an Out parameter
	with Default_Value aspect is passed in by copy.


-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-patch
Size: 1295 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140125/f7863470/attachment.bin>


More information about the Gcc-patches mailing list