https://gcc.gnu.org/g:c2b3d5e23ec92fca5852d607a4e2348fb011f3a7

commit r16-4721-gc2b3d5e23ec92fca5852d607a4e2348fb011f3a7
Author: Eric Botcazou <[email protected]>
Date:   Thu Oct 30 00:33:36 2025 +0100

    Ada: Fix spurious visibility issue with qualified aggregate in instantiation
    
    Aggregates used as actuals of formal object parameters are handled specially
    by Instantiate_Object in Sem_Ch12 and qualifying them is sufficient to block
    this special processing.
    
    gcc/ada/
            PR ada/54178
            * sem_ch12.adb (Instantiate_Object): Strip qualification to detect
            aggregates used as actuals.
    
    gcc/testsuite/
            * gnat.dg/aggr32.adb: New test.
            * gnat.dg/aggr32_pkg.ads: New helper.
            * gnat.dg/aggr32_pkg-child.ads: Likewise.

Diff:
---
 gcc/ada/sem_ch12.adb                       |  2 +-
 gcc/testsuite/gnat.dg/aggr32.adb           | 15 +++++++++++++++
 gcc/testsuite/gnat.dg/aggr32_pkg-child.ads |  6 ++++++
 gcc/testsuite/gnat.dg/aggr32_pkg.ads       |  8 ++++++++
 4 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index cbb0debbf1fb..deb19ee118e1 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -13223,7 +13223,7 @@ package body Sem_Ch12 is
                --  to capture local names that may be hidden if the generic is
                --  a child unit.
 
-               if Nkind (Actual) = N_Aggregate then
+               if Nkind (Unqualify (Actual)) = N_Aggregate then
                   Preanalyze_And_Resolve (Actual, Typ);
                end if;
 
diff --git a/gcc/testsuite/gnat.dg/aggr32.adb b/gcc/testsuite/gnat.dg/aggr32.adb
new file mode 100644
index 000000000000..e5b0887f59c9
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/aggr32.adb
@@ -0,0 +1,15 @@
+-- { dg-do compile }
+
+with Aggr32_Pkg.Child;
+
+procedure Aggr32 (W, H : Positive) is
+
+  use Aggr32_Pkg;
+
+  package Test_1 is new Child (Frame => (Width => W, Height => H));
+
+  package Test_2 is new Child (Frame => Rec'(Width => W, Height => H));
+
+begin
+  null;
+end;
diff --git a/gcc/testsuite/gnat.dg/aggr32_pkg-child.ads 
b/gcc/testsuite/gnat.dg/aggr32_pkg-child.ads
new file mode 100644
index 000000000000..352e2b518e1f
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/aggr32_pkg-child.ads
@@ -0,0 +1,6 @@
+generic
+
+  Frame : Rec;
+
+package Aggr32_Pkg.Child is
+end Aggr32_Pkg.Child;
diff --git a/gcc/testsuite/gnat.dg/aggr32_pkg.ads 
b/gcc/testsuite/gnat.dg/aggr32_pkg.ads
new file mode 100644
index 000000000000..e0e8bef9837f
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/aggr32_pkg.ads
@@ -0,0 +1,8 @@
+package Aggr32_Pkg is
+
+  type Rec is record
+    Width  : Positive;
+    Height : Positive;
+  end record;
+
+end Aggr32_Pkg;

Reply via email to