aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2009-04-20 14:54:05 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2009-04-20 14:54:05 +0200
commita3c39f83ee9d05fa4ee14288ce1758eb4bb7f912 (patch)
treeb0d93a2a215868b823f74dc6a29f436a5e54ae32
parent4f18d8607e6c2ad919ea442934ba367e4f8a35d2 (diff)
downloadgcc-a3c39f83ee9d05fa4ee14288ce1758eb4bb7f912.zip
gcc-a3c39f83ee9d05fa4ee14288ce1758eb4bb7f912.tar.gz
gcc-a3c39f83ee9d05fa4ee14288ce1758eb4bb7f912.tar.bz2
sem_ch8.adb (Analyze_Object_Renaming): Proper checks on incorrect null exclusion qualifiers for object renaming...
2009-04-20 Ed Schonberg <schonberg@adacore.com> * sem_ch8.adb (Analyze_Object_Renaming): Proper checks on incorrect null exclusion qualifiers for object renaming declarations. From-SVN: r146409
-rw-r--r--gcc/ada/sem_ch8.adb50
1 files changed, 43 insertions, 7 deletions
diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index 56b5543..88eed1d 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -954,14 +954,21 @@ package body Sem_Ch8 is
-- declaration occurs within the body of G or within the body
-- of a generic unit declared within the declarative region
-- of G, then the declaration of the formal object of G must
- -- have a null exclusion.
+ -- have a null exclusion or a null-excluding subtype.
if Is_Formal_Object (Nam_Ent)
and then In_Generic_Scope (Id)
then
- Error_Msg_N
- ("renamed formal does not exclude `NULL` "
- & "(RM 8.5.1(4.6/2))", N);
+ if not Can_Never_Be_Null (Etype (Nam_Ent)) then
+ Error_Msg_N
+ ("renamed formal does not exclude `NULL` "
+ & "(RM 8.5.1(4.6/2))", N);
+
+ elsif In_Package_Body (Scope (Id)) then
+ Error_Msg_N
+ ("formal object does not have a null exclusion"
+ & "(RM 8.5.1(4.6/2))", N);
+ end if;
-- Ada 2005 (AI-423): Otherwise, the subtype of the object name
-- shall exclude null.
@@ -971,13 +978,42 @@ package body Sem_Ch8 is
("renamed object does not exclude `NULL` "
& "(RM 8.5.1(4.6/2))", N);
- elsif Can_Never_Be_Null (Etype (Nam_Ent)) then
+ -- An instance is illegal if it contains a renaming that
+ -- excludes null, and the actual does not. The renaming
+ -- declaration has already indicated that the declaration
+ -- of the renamed actual in the instance will raise
+ -- constraint_error.
+
+ elsif Nkind (Parent (Nam_Ent)) = N_Object_Declaration
+ and then In_Instance
+ and then Present
+ (Corresponding_Generic_Association (Parent (Nam_Ent)))
+ and then Nkind (Expression (Parent (Nam_Ent)))
+ = N_Raise_Constraint_Error
+ then
+ Error_Msg_N
+ ("renamed actual does not exclude `NULL` "
+ & "(RM 8.5.1(4.6/2))", N);
+
+ -- Finally, if there is a null exclusion, the subtype mark
+ -- must not be null-excluding.
+
+ elsif No (Access_Definition (N))
+ and then Can_Never_Be_Null (T)
+ then
Error_Msg_NE
- ("`NOT NULL` not allowed (type of& already excludes null)",
- N, Nam_Ent);
+ ("`NOT NULL` not allowed (& already excludes null)",
+ N, T);
end if;
+ elsif Can_Never_Be_Null (T)
+ and then not Can_Never_Be_Null (Etype (Nam_Ent))
+ then
+ Error_Msg_N
+ ("renamed object does not exclude `NULL` "
+ & "(RM 8.5.1(4.6/2))", N);
+
elsif Has_Null_Exclusion (N)
and then No (Access_Definition (N))
and then Can_Never_Be_Null (T)