Comments
Patch
===================================================================
@@ -507,13 +507,21 @@
-- be a null object, and we can insert an unconditional raise
-- before the allocator.
+ -- Ada2012 (AI-104) : a not null indication here is altogether
+ -- illegal.
+
if Can_Never_Be_Null (Type_Id) then
declare
Not_Null_Check : constant Node_Id :=
Make_Raise_Constraint_Error (Sloc (E),
Reason => CE_Null_Not_Allowed);
begin
- if Expander_Active then
+ if Ada_Version >= Ada_12 then
+ Error_Msg_N
+ ("an uninitialized allocator cannot have"
+ & " a null exclusion", N);
+
+ elsif Expander_Active then
Insert_Action (N, Not_Null_Check);
Analyze (Not_Null_Check);
else
If Some_Ptr is an access type, the following allocator: Ptr := new Some_Ptr; creates a pointer to a null value. Therefore, the construct: Ptr := new not null Some_Ptr; is known to raise Constraint_Error. This useless construct has been declared illegal in Ada2012. Compiling the following program must yield: alloc.adb:7:13: an uninitialized allocator cannot have a null exclusion --- procedure Alloc is 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; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-07 Ed Schonberg <schonberg@adacore.com> * sem_ch4.adb (Analyze_Allocator): In Ada 2012, a null_exclusion indicator is illegal for an uninitialized allocator.