public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Spurious error on subtypes of private tagged types
@ 2017-04-25  8:25 Arnaud Charlet
  0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2017-04-25  8:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Javier Miranda

[-- Attachment #1: Type: text/plain, Size: 1170 bytes --]

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.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 650 bytes --]

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)));

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-04-25  8:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-25  8:25 [Ada] Spurious error on subtypes of private tagged types Arnaud Charlet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).