https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129058

            Bug ID: 129058
           Summary: global names in iterated component association of
                    aggregate not resolved in instance of library-level
                    generic (follow-up to PR ada/128723)
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johann.blieberger at tuwien dot ac.at
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 66296
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66296&action=edit
g.ads

The fix for PR ada/128723 (commit 8be8dad4609, "Fix wrong resolution for
iterated expression of aggregate in instance") makes the expression of an
iterated component association be preanalyzed directly inside a generic,
so that its global references are captured. This works when the generic
is declared in the same compilation unit as the instantiation (as in the
new test gnat.dg/aggr36.adb), but not when the generic is a library unit
of its own: the names in the expression are then resolved again at the
instantiation, where the context clauses of the generic unit are not
visible.

Reproducer (two files):

-- g.ads
with Ada.Strings.Unbounded;
generic
package G is
   type Arr is array (1 .. 3) of Ada.Strings.Unbounded.Unbounded_String;
   A : constant Arr :=
     [for I in Arr'Range => Ada.Strings.Unbounded.To_Unbounded_String ("x")];
end G;

-- main.adb
with G;
procedure Main is
   package I is new G;
begin
   null;
end Main;

$ gcc -c -gnat2022 main.adb
main.adb:3:04: error: instantiation error at g.ads:6
main.adb:3:04: error: "Ada" is not visible
main.adb:3:04: error: instantiation error at g.ads:6
main.adb:3:04: error: non-visible declaration at ada.ads:18

GCC 14.4.1 compiles both files without error.

The same happens when the generic unit makes the names visible by a use
clause in its context clause ("To_Unbounded_String is not visible"), and
for a generic package body in a separate file whose context clause has the
use clause (found in a real project: a generic body with
"use Ada.Strings.Wide_Unbounded;" and an aggregate
"[for I in R'Range => (To_Unbounded_Wide_String (...), ...)]"). A use
clause inside the generic unit, or a nested generic, compiles.

Reproduced with a plain build of the releases/gcc-16 branch (xgcc (GCC)
16.2.1 20261120, which contains commit 8be8dad4609), x86_64-pc-linux-gnu,
configured with --enable-languages=c,ada --disable-bootstrap. Not
checked with GCC 15 or the main branch.

Reply via email to