[Ada] Spurious visibility error in generic child unit
authorEd Schonberg <schonberg@adacore.com>
Thu, 19 Sep 2019 08:14:08 +0000 (08:14 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Thu, 19 Sep 2019 08:14:08 +0000 (08:14 +0000)
2019-09-19  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

* sem_ch7.adb (Install_Parent_Private_Declarations): If a
generic child unit is instantiated within a sibling child unit,
the analysis of its private part requires that the private part
of the ancestor be available, as is done when the context
includes an instance of the ancestor.

gcc/testsuite/

* gnat.dg/generic2-child.ads, gnat.dg/generic2-io_any.adb,
gnat.dg/generic2-io_any.ads, gnat.dg/generic2.ads: New testcase.

From-SVN: r275949

gcc/ada/ChangeLog
gcc/ada/sem_ch7.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/generic2-child.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/generic2-io_any.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/generic2-io_any.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/generic2.ads [new file with mode: 0644]

index 8c88e9061056c8d2ca44eef2ac1dfa357f88f5b6..e761f701fe7d7ee65aefc437c1e1b1b8d4aa3ebb 100644 (file)
@@ -1,3 +1,11 @@
+2019-09-19  Ed Schonberg  <schonberg@adacore.com>
+
+       * sem_ch7.adb (Install_Parent_Private_Declarations): If a
+       generic child unit is instantiated within a sibling child unit,
+       the analysis of its private part requires that the private part
+       of the ancestor be available, as is done when the context
+       includes an instance of the ancestor.
+
 2019-09-19  Yannick Moy  <moy@adacore.com>
 
        * inline.adb (Can_Be_Inlined_In_GNATprove_Mode): Add special
index f7998c0d75bd105270504769e00a74790d0312cf..db6bffd96740753f5513c6123cf310232b216bce 100644 (file)
@@ -1508,9 +1508,21 @@ package body Sem_Ch7 is
                   Inst_Par := Renamed_Entity (Inst_Par);
                end if;
 
-               Gen_Par :=
-                 Generic_Parent
-                   (Specification (Unit_Declaration_Node (Inst_Par)));
+               --  The instance may appear in a sibling generic unit, in
+               --  which case the prefix must include the common (generic)
+               --  ancestor, which is treated as a current instance.
+
+               if Inside_A_Generic
+                 and then Ekind (Inst_Par) = E_Generic_Package
+               then
+                  Gen_Par := Inst_Par;
+                  pragma Assert (In_Open_Scopes (Gen_Par));
+
+               else
+                  Gen_Par :=
+                    Generic_Parent
+                      (Specification (Unit_Declaration_Node (Inst_Par)));
+               end if;
 
                --  Install the private declarations and private use clauses
                --  of a parent instance of the child instance, unless the
index da23e2cd5af1b2b9231ce89ccbe94452c5e1a97f..a3534f1442f7fb0504df947262c60f84eb0137be 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-19  Ed Schonberg  <schonberg@adacore.com>
+
+       * gnat.dg/generic2-child.ads, gnat.dg/generic2-io_any.adb,
+       gnat.dg/generic2-io_any.ads, gnat.dg/generic2.ads: New testcase.
+
 2019-09-19  Yannick Moy  <moy@adacore.com>
 
        * gnat.dg/global2.adb, gnat.dg/global2.ads: New testcase.
diff --git a/gcc/testsuite/gnat.dg/generic2-child.ads b/gcc/testsuite/gnat.dg/generic2-child.ads
new file mode 100644 (file)
index 0000000..291cb23
--- /dev/null
@@ -0,0 +1,5 @@
+generic
+package Generic2.Child is
+private
+  type My_Int is new Int;
+end Generic2.Child;
diff --git a/gcc/testsuite/gnat.dg/generic2-io_any.adb b/gcc/testsuite/gnat.dg/generic2-io_any.adb
new file mode 100644 (file)
index 0000000..f077ad6
--- /dev/null
@@ -0,0 +1,5 @@
+--  { dg-do compile }
+
+package body Generic2.IO_Any is
+  procedure Dummy is null;
+end Generic2.IO_Any;
\ No newline at end of file
diff --git a/gcc/testsuite/gnat.dg/generic2-io_any.ads b/gcc/testsuite/gnat.dg/generic2-io_any.ads
new file mode 100644 (file)
index 0000000..e56e229
--- /dev/null
@@ -0,0 +1,6 @@
+with Generic2.Child;
+generic
+package Generic2.IO_Any is
+  package V1 is new Generic2.Child;
+  procedure Dummy;
+end Generic2.IO_Any;
diff --git a/gcc/testsuite/gnat.dg/generic2.ads b/gcc/testsuite/gnat.dg/generic2.ads
new file mode 100644 (file)
index 0000000..295d6b2
--- /dev/null
@@ -0,0 +1,5 @@
+generic
+package Generic2 is
+private
+  type Int is new Integer;
+end Generic2;