[Ada] Spurious error on subtypes of private tagged types

Arnaud Charlet charlet@adacore.com
Tue Apr 25 08:25:00 GMT 2017


When a private tagged record type has some component whose type is
the public declaration of a private subtype the compiler may report
an spurious error on invalid conversion. The same error may be also
reported on package instantiations when the actual type of some
generic formal is a private type that is used in the instantiation
to declare a component of a tagged type declaration.

After this patch the following test compiles without errors.

package Pkg1 is
   type Bounded_String is private;
private
   type Super_String (Max_Length : Positive) is record null; end record;
   type Bounded_String is new Super_String (10);
end;

with Pkg1;
package Pkg2 is
   type Key_Type is private;
private
   type Key_Type is new Pkg1.Bounded_String;
end;

package Pkg2.Child is
   subtype A_T is Key_Type;       -- Test
private
   type Derived is tagged record
      X : A_T;                    -- Test
   end record;
end;

Command: gcc -c pkg2-child.ads

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

2017-04-25  Javier Miranda  <miranda@adacore.com>

	* exp_attr.adb (Rewrite_Stream_Proc_Call): Handle
	subtypes of private types when performing the view conversion.

-------------- next part --------------
Index: exp_attr.adb
===================================================================
--- exp_attr.adb	(revision 247135)
+++ exp_attr.adb	(working copy)
@@ -1650,8 +1650,8 @@
             --  Perform a view conversion when either the argument or the
             --  formal parameter are of a private type.
 
-            if Is_Private_Type (Formal_Typ)
-              or else Is_Private_Type (Item_Typ)
+            if Is_Private_Type (Base_Type (Formal_Typ))
+              or else Is_Private_Type (Base_Type (Item_Typ))
             then
                Rewrite (Item,
                  Unchecked_Convert_To (Formal_Typ, Relocate_Node (Item)));


More information about the Gcc-patches mailing list