From: "Peter C. Chapin" <pchapin@sover.net>
Subject: Another question about controlled types.
Date: Sat, 09 Feb 2008 15:57:22 -0500
Date: 2008-02-09T15:57:22-05:00 [thread overview]
Message-ID: <47ae13b2$0$32493$4d3efbfe@news.sover.net> (raw)
I'm using GNAT GPL 2007. I understand that Ada 2005 allows one to return
limited types from functions. Consider the following package
specification and body:
package Check is
type Some_Type is limited private;
function Make(I : Integer) return Some_Type;
private
type Some_Type is
record
Component : Integer;
end record;
end Check;
package body Check is
function Make(I : Integer) return Some_Type is
Result : Some_Type;
begin
Result.Component := I;
return Result;
end Make;
end Check;
In fact, this compiles fine using "gnatmake -gnatc check.adb"
Now consider the following slight (but significant!) change to the
specification:
with Ada.Finalization;
package Check is
type Some_Type is limited private;
function Make(I : Integer) return Some_Type;
private
type Some_Type is new Ada.Finalization.Limited_Controlled with
record
Component : Integer;
end record;
end Check;
In this case the full view of Some_Type is controlled. Now when I
attempt to compile the package I get:
check.adb:8:14: (Ada 2005) cannot copy object of a limited type (RM-2005
6.5(5.5/2))
check.adb:8:14: return by reference not permitted in Ada 2005
check.adb:8:14: consider switching to return of access type
I'm not sure why there is a problem now. I tried declaring Some_Type as
tagged in the visible part of the package but that didn't help.
Peter
next reply other threads:[~2008-02-09 20:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-09 20:57 Peter C. Chapin [this message]
2008-02-09 21:50 ` Another question about controlled types Jeffrey R. Carter
2008-02-09 23:41 ` Peter C. Chapin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox