package pak1 is type T1 is interface; type T2 is tagged null record; x1: access T1'Class; x2: T2 := T2(T2'class(x1.all)); --OK x3: T2 := T2(x1.all); --ERROR: not a valid type conversion end pak1;
The declaration of x2 is a legal type conversion, because x1.all and T2'class both have class-wide types, so RM 4.6(21/2) applies. But the declaration of x3 isn't a legal type conversion because T2 isn't classwide, so RM 4.6(24/2) applies instead, which doesn't offer any reason for this to be legal. GCC 4.3 fails to diagnose the violation of 4.6(24/2), instead warning about null access values: gcc-4.3 -c -gnat05 pak1.ads pak1.ads:5:26: warning: null value not allowed here pak1.ads:5:26: warning: "Constraint_Error" will be raised at run time pak1.ads:6:17: warning: null value not allowed here pak1.ads:6:17: warning: "Constraint_Error" will be raised at run time Here, gcc seems to propagate x1's null value even before considering whether the type conversions are legal. -- Summary: Illegal program not detected, RM 4.6(24/2) Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ludovic at ludovic-brenta dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35984