[Ada] Ada 2012 AIo5-014: no null exclusion on allocator with subtype indication

Submitted by Arnaud Charlet on Dec. 5, 2012, 11:09 a.m.


Message ID 20121205110935.GA23612@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Dec. 5, 2012, 11:09 a.m.
The patch implements properly the rule given in this Ada issue. The check is
purely syntactic and does not depend on whether the designated type is itself a
null excluding access type.

Compiling the following in Ada 2012 mode must yield:
         an allocator with a subtype indication cannot have a null exclusion

--  AI05-104 : an uninitialzed allocated cannot carry a null exclusion.

procedure Alloc is
      type R (D : Integer) is record
         Val : Integer;
      end record;

      type Ptr is not null access all R;
      if new Ptr  /= null then   --  OK
         raise Program_Error;
      end if;

      type T is tagged null record;
      type Ptr is access all T;
      type Link is access all Ptr;
      Thing : Link;
      Thing := new not null Ptr;   --  Error

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

2012-12-05  Ed Schonberg  <schonberg@adacore.com>

	* par-ch4.adb (P_Allocator): In Ada 2012 (AI05-0104)  an
	uninitialized allocator cannot carry an explicit not null
	* sem_ch4.adb (Analyze_Allocator): Remove code that implements
	the check for AI05-0104, the check is syntactic and performed
	in the parser.

Patch hide | download patch | download mbox

Index: par-ch4.adb
--- par-ch4.adb	(revision 194207)
+++ par-ch4.adb	(working copy)
@@ -2928,6 +2928,18 @@ 
             P_Subtype_Indication (Type_Node, Null_Exclusion_Present));
+         --  AI05-0104 :  an explicit null exclusion is not allowed for an
+         --  allocator without initialization. In previous versions of the
+         --  language it just raises constraint error.
+         if Ada_Version >= Ada_2012
+           and then Null_Exclusion_Present
+         then
+            Error_Msg_N
+              ("an allocator with a subtype indication "
+                & "cannot have a null exclusion", Alloc_Node);
+         end if;
       end if;
       return Alloc_Node;
Index: sem_ch4.adb
--- sem_ch4.adb	(revision 194204)
+++ sem_ch4.adb	(working copy)
@@ -631,12 +631,7 @@ 
                                        Reason => CE_Null_Not_Allowed);
-                  if Ada_Version >= Ada_2012 then
-                     Error_Msg_N
-                       ("an uninitialized allocator cannot have"
-                         & " a null exclusion", N);
-                  elsif Expander_Active then
+                  if Expander_Active then
                      Insert_Action (N, Not_Null_Check);
                      Analyze (Not_Null_Check);