Comments
Patch
===================================================================
@@ -2928,6 +2928,18 @@
Set_Expression
(Alloc_Node,
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;
===================================================================
@@ -631,12 +631,7 @@
Reason => CE_Null_Not_Allowed);
begin
- 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);
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: alloc.adb:23:16: an allocator with a subtype indication cannot have a null exclusion --- -- AI05-104 : an uninitialzed allocated cannot carry a null exclusion. procedure Alloc is begin declare type R (D : Integer) is record Val : Integer; end record; type Ptr is not null access all R; begin if new Ptr /= null then -- OK raise Program_Error; end if; end; declare type T is tagged null record; type Ptr is access all T; type Link is access all Ptr; Thing : Link; begin Thing := new not null Ptr; -- Error end; end; 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 indicator. * sem_ch4.adb (Analyze_Allocator): Remove code that implements the check for AI05-0104, the check is syntactic and performed in the parser.