[Ada] Spurious visibility error in predicate in generic instance

Message ID 20191010152946.GA87486@adacore.com
State New
Headers show
  • [Ada] Spurious visibility error in predicate in generic instance
Related show

Commit Message

Pierre-Marie de Rodat Oct. 10, 2019, 3:29 p.m.
Compilation_Unit pragmas that appear after the corresponding unit are
analyzed before the declarations in the unit, in order to set proper
categorization flags and verify that they are respected by those
declarations. If the unit is a child unit and also the instance of a
generic child unit the parent unit may have to become visible during the
analysis of the pragma.

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

2019-10-10  Ed Schonberg  <schonberg@adacore.com>


	* sem_cat.adb (Set_Categorization_From_Pragma): Do not modify
	any visibility settings if there are no compilation_unit pragmas
	following the package declaration. Add comments for future


--- gcc/ada/sem_cat.adb
+++ gcc/ada/sem_cat.adb
@@ -721,9 +721,15 @@  package body Sem_Cat is
       --  The purpose is to set categorization flags before analyzing the
       --  unit itself, so as to diagnose violations of categorization as
       --  we process each declaration, even though the pragma appears after
-      --  the unit.
-      if Nkind (P) /= N_Compilation_Unit then
+      --  the unit. This processing is only needsd if compilation unit
+      --  pragmas are present.
+      --  Note: this code may be incorrect in the unlikely case a child
+      --  genericc unit is instantiated as a child of its (non-generic)
+      --  parent, so that generic and insstance are siblings,
+      if Nkind (P) /= N_Compilation_Unit
+         or else No (First (Pragmas_After (Aux_Decls_Node (P))))
+      then
       end if;