In routine Process_Subtype we had two calls to Null_Exclusion_Present
(P): one guarded by "Present (P)" and the other by "Nkind (P) in ...".
Now both calls are guarded by the conjunction of those guards.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

        * sem_ch3.adb (Process_Subtype): Combine guards for
        Null_Exclusion_Present in May_Have_Null_Exclusion; use this
        combined guard when checking AI-231.
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -21541,21 +21541,12 @@ package body Sem_Ch3 is
          Check_Incomplete (S);
          P := Parent (S);
 
-         --  Ada 2005 (AI-231): Static check
-
-         if Ada_Version >= Ada_2005
-           and then Present (P)
-           and then Null_Exclusion_Present (P)
-           and then Nkind (P) /= N_Access_To_Object_Definition
-           and then not Is_Access_Type (Entity (S))
-         then
-            Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
-         end if;
-
          --  The following mirroring of assertion in Null_Exclusion_Present is
          --  ugly, can't we have a range, a static predicate or even a flag???
 
          May_Have_Null_Exclusion :=
+           Present (P)
+             and then
            Nkind (P) in N_Access_Definition
                       | N_Access_Function_Definition
                       | N_Access_Procedure_Definition
@@ -21571,6 +21562,17 @@ package body Sem_Ch3 is
                       | N_Parameter_Specification
                       | N_Subtype_Declaration;
 
+         --  Ada 2005 (AI-231): Static check
+
+         if Ada_Version >= Ada_2005
+           and then May_Have_Null_Exclusion
+           and then Null_Exclusion_Present (P)
+           and then Nkind (P) /= N_Access_To_Object_Definition
+           and then not Is_Access_Type (Entity (S))
+         then
+            Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
+         end if;
+
          --  Create an Itype that is a duplicate of Entity (S) but with the
          --  null-exclusion attribute.
 


Reply via email to