The following does not compile: package Test is type X is new Positive; type X_Access is not null access constant X;
Y : constant X_Access; private Y_Val : aliased constant X := 1; Y : constant X_Access := Y_Val'Access; end Test; with the following diagnostics: test.ads:6:09: warning: (Ada 2005) null-excluding objects must be initialized test.ads:6:09: warning: "Constraint_Error" will be raised at run time test.ads:11:09: "Y" conflicts with declaration at line 6 If "not null" modifier is removed, everything is fine. As I can see from the following code, the semantic analyzer sees a deferred constant and (erroneously) assumes that it's an uninitialized object. It then inserts an implicit null initialization. And when it comes to a full definition of the constant, the compiler thinks it has been already defined: (gcc/ada/checks.adb, procedure Null_Exclusion_Static_Checks, line 2728): if K = N_Object_Declaration and then No (Expression (N)) and then not No_Initialization (N) then -- Add an expression that assigns null. This node is needed by -- Apply_Compile_Time_Constraint_Error, which will replace this with -- a Constraint_Error node. Set_Expression (N, Make_Null (Sloc (N))); Set_Etype (Expression (N), Etype (Defining_Identifier (N))); Apply_Compile_Time_Constraint_Error (N => Expression (N), Msg => "(Ada 2005) null-excluding objects must be initialized?", Reason => CE_Null_Not_Allowed); end if; The code can be traced back to at least gcc 4.1.2 -- Summary: deferred constants of not null access types are not possible Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Artem dot Andreev at oktetlabs dot ru http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38975