comp.lang.ada
 help / color / mirror / Atom feed
From: anon@att.net
Subject: Re: A hole in Ada type safety
Date: Tue, 10 May 2011 06:27:44 +0000 (UTC)
Date: 2011-05-10T06:27:44+00:00	[thread overview]
Message-ID: <iqalsu$6nl$1@speranza.aioe.org> (raw)
In-Reply-To: m2y62g7v92.fsf@pushface.org

Better look again!

Even though a compiler emulates the "Unchecked_Conversion" with a built-in 
"pragma inline" being enforced.  The function still must be able to be 
written in Ada. That goes back to the origins of Ada and has not change. 
Plus, the function's source code can be inserted into a routine or 
re-named for use or testing of this routine. That is also apart of Ada.

Any programmer should be able to simulated the Unchecked_Conversion 
function in Ada (non GNAT), such as:

      pragma Suppress ( All_Checks ) ;    -- Ada 95/2005
      Target_Object := Target ( Source_Object ) ;
      pragma Unsuppress ( All_Checks ) ;  -- Ada 95/2005

Now, in Ada 83 there was no way to turn the checks back on after they
were suppressed. The exception was to use a function where the scope of 
the suppressed checks would be limited to that function only, thus a 
reason for the creation of the generic "Unchecked_Conversion" function.


The body of the "Unchecked_Conversion" function is:

---------------------------------------
  function Unchecked_Conversion ( S : Source ) 
           return Target is

      -- Ada 83 a Suppress statement per check must be given
      -- 
      pragma Suppress ( All_Checks ) ; 

    begin
      --  This statement should compile because all checks have been 
      --  turn off. Even without checks this routine must still comply 
      --  with type conversion rules set in RM 4.6, which can limited
      --  or restriction the conversion. 
      --
      --  Starting with Ada 95 the semantic and expansion analysis 
      --  must also, insure that the additional rules RM 13.9 
      --  ( 5 .. 10 ) are enforced. Since these rules can be derived
      --  from the legal rules for type conversion ( RM 4.6 ), these
      --  checks can be done in the while evaluating the type 
      --  conversion expression.
      --
      --  Ada 83, RM 13.10.2 ( 3 ) states the programmer is 
      --  "responsibility to ensure that these conversions maintain
      --  the properties that are guaranteed by the language for 
      --  objects of the target type." But the vendor can set
      --  restrictions.
      --
      return Target ( S ) ;
  end Unchecked_Conversion ;
---------------------------------------

Now in Ada 2005, RM 7.5 (1/2) states that a routine can not just copy
a "limited private" object. RM 6.5 (5.1/2, 5.c/2 ) states that if 
the target is limited the function "must produce a ""new"" object" 
instead of just copying the object.

Aka the "Unchecked_Conversion" which is a generic function is no 
longer just an inlined expression that is just a type conversions 
with all checks being disable. The function must now return a "new" 
object RM 6.5 (5.5/2, 5.c/2 ), by first requesting an new object 
from the Target's storage pool and then copying the Source data to 
that new object. So, in Ada 2005 the "Unchecked_Conversion" must be 
handled as a true generic function with a true return, instead of a 
built-in inline expression.

But GNAT still just performs a simple copy. So, is GNAT or the RM 
or is the generic "Unchecked_Conversion" function in error?


In <m2y62g7v92.fsf@pushface.org>, Simon Wright <simon@pushface.org> writes:
>anon@att.net writes:
>
>> Your two programs has pointed out a puzzle in the RM-2005.  And that is 
>> does the definition of the standard Generic package Unchecked_Conversion 
>> violate the RM (6.5/(5.5/2). 
>
>"I beseech you, in the bowels of Christ, think it possible that you may
> be mistaken."
> O. Cromwell, 1650.




  reply	other threads:[~2011-05-10  6:27 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-30  8:41 A hole in Ada type safety Florian Weimer
2011-04-30 11:56 ` Robert A Duff
2011-04-30 15:27   ` Gavino
2011-04-30 16:16   ` Florian Weimer
2011-04-30 23:39     ` Randy Brukardt
2011-05-01 10:26       ` Florian Weimer
2011-05-03  1:40         ` Randy Brukardt
2011-05-03 16:57           ` Robert A Duff
2011-05-07  9:09           ` Florian Weimer
2011-05-07  9:28             ` Dmitry A. Kazakov
2011-05-07  9:57               ` Florian Weimer
2011-05-08  8:08                 ` Dmitry A. Kazakov
2011-05-08  8:46                   ` Florian Weimer
2011-05-08  9:32                     ` Dmitry A. Kazakov
2011-05-08 10:30                       ` Florian Weimer
2011-05-08 20:24                         ` anon
2011-05-08 21:11                           ` Simon Wright
2011-05-10  6:27                             ` anon [this message]
2011-05-10 14:39                               ` Adam Beneschan
2011-05-11 20:39                                 ` anon
2011-05-12  0:51                                   ` Randy Brukardt
2011-05-13  0:47                                     ` anon
2011-05-13  0:58                                       ` Adam Beneschan
2011-05-13  5:31                                       ` AdaMagica
2011-05-12  5:51                                   ` AdaMagica
2011-05-12 12:09                                     ` Robert A Duff
2011-05-12 14:40                                     ` Adam Beneschan
2011-05-14  0:30                                       ` Randy Brukardt
2011-05-09  7:48                         ` Dmitry A. Kazakov
2011-05-09 20:41             ` Randy Brukardt
2011-05-14 23:47     ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox