aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch8.adb
diff options
context:
space:
mode:
authorGary Dismukes <dismukes@adacore.com>2011-08-30 13:16:22 +0000
committerArnaud Charlet <charlet@gcc.gnu.org>2011-08-30 15:16:22 +0200
commit6cce215622c7a24991d7c90d743cc82cc1b0d76c (patch)
treee0000a0cf72df374303078147d1c94eff72b0539 /gcc/ada/sem_ch8.adb
parente12da14140bd1ec670a97f2e9b147d16e81c8ae4 (diff)
downloadgcc-6cce215622c7a24991d7c90d743cc82cc1b0d76c.zip
gcc-6cce215622c7a24991d7c90d743cc82cc1b0d76c.tar.gz
gcc-6cce215622c7a24991d7c90d743cc82cc1b0d76c.tar.bz2
sem_ch6.adb (Check_Return_Subtype_Indication): Issue error if the return object has an anonymous access type and the...
2011-08-30 Gary Dismukes <dismukes@adacore.com> * sem_ch6.adb (Check_Return_Subtype_Indication): Issue error if the return object has an anonymous access type and the function's type is a named access type. * sem_ch8.adb (Analyze_Object_Renaming): Suppress error about renaming conversions on implicit conversions, since such conversions can occur for anonymous access cases due to expansion. Issue error for attempt to rename an anonymous expression as an object of a named access type. * sem_res.ads (Valid_Conversion): Add defaulted parameter Report_Errs, to indicate whether this function should report errors on invalid conversions. * sem_res.adb (Resolve): For Ada 2012, in the case where the type of the expression is of an anonymous access type and the expected type is a named general access type, rewrite the expression as a type conversion, unless this is an expression of a membership test. (Valid_Conversion.Error_Msg_N): New procedure that conditions the calling of Error_Msg_N on new formal Report_Errs. (Valid_Conversion.Error_Msg_NE): New procedure that conditions the calling of Error_Msg_NE on new formal Report_Errs. (Valid_Conversion): Move declaration of this function to the package spec, to allow calls from membership test processing. For Ada 2012, enforce legality restrictions on implicit conversions of anonymous access values to general access types, disallowing such conversions in cases where the expression has a dynamic accessibility level (access parameters, stand-alone anonymous access objects, or a component of a dereference of one of the first two cases). * sem_type.adb (Covers): For Ada 2012, allow an anonymous access type in the context of a named general access expected type. * exp_ch4.adb Add with and use of Exp_Ch2. (Expand_N_In): Add processing for membership tests applied to expressions of an anonymous access type. First, Valid_Conversion is called to check whether the test is statically False, and then the conversion is expanded to test that the expression's accessibility level is no deeper than that of the tested type. In the case of anonymous access-to-tagged types, a tagged membership test is applied as well. (Tagged_Membership): Extend to handle access type cases, applying the test to the designated types. * exp_ch6.adb (Expand_Call): When creating an extra actual for an accessibility level, and the actual is a 'Access applied to a current instance, pass the accessibility level of the type of the current instance rather than applying Object_Access_Level to the prefix. Add a ??? comment, since this level isn't quite right either (will eventually need to pass an implicit level parameter to init procs). From-SVN: r178296
Diffstat (limited to 'gcc/ada/sem_ch8.adb')
-rw-r--r--gcc/ada/sem_ch8.adb23
1 files changed, 22 insertions, 1 deletions
diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index 77f948f..662a0e9 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -802,8 +802,13 @@ package body Sem_Ch8 is
T := Entity (Subtype_Mark (N));
Analyze (Nam);
+ -- Reject renamings of conversions unless the type is tagged, or
+ -- the conversion is implicit (which can occur for cases of anonymous
+ -- access types in Ada 2012).
+
if Nkind (Nam) = N_Type_Conversion
- and then not Is_Tagged_Type (T)
+ and then Comes_From_Source (Nam)
+ and then not Is_Tagged_Type (T)
then
Error_Msg_N
("renaming of conversion only allowed for tagged types", Nam);
@@ -834,6 +839,22 @@ package body Sem_Ch8 is
return;
end if;
+ -- Ada 2012 (AI05-149): Reject renaming of an anonymous access object
+ -- when renaming declaration has a named access type. The Ada 2012
+ -- coverage rules allow an anonymous access type in the context of
+ -- an expected named general access type, but the renaming rules
+ -- require the types to be the same. (An exception is when the type
+ -- of the renaming is also an anonymous access type, which can only
+ -- happen due to a renaming created by the expander.)
+
+ if Nkind (Nam) = N_Type_Conversion
+ and then not Comes_From_Source (Nam)
+ and then Ekind (Etype (Expression (Nam))) = E_Anonymous_Access_Type
+ and then Ekind (T) /= E_Anonymous_Access_Type
+ then
+ Wrong_Type (Expression (Nam), T); -- Should we give better error???
+ end if;
+
-- Check that a class-wide object is not being renamed as an object
-- of a specific type. The test for access types is needed to exclude
-- cases where the renamed object is a dynamically tagged access