public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r15-682] ada: Error on instantiation of generic containing legal container aggregate
@ 2024-05-20  7:50 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2024-05-20  7:50 UTC (permalink / raw)
  To: gcc-cvs

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

commit r15-682-gd1e3aae37894079ebd0be2a6baccce5a89a251c3
Author: Gary Dismukes <dismukes@adacore.com>
Date:   Tue Mar 26 01:01:57 2024 +0000

    ada: Error on instantiation of generic containing legal container aggregate
    
    When a container aggregate for a predefined container type (such as
    a Vector type) that has an iterated component association occurs within
    a generic unit and that generic is instantiated, the compiler reports
    a spurious error message "iterated component association can only appear
    in an array aggregate" and the compilation aborts (because Unrecoverable_Error
    is raised unconditionally after that error). The problem is that as part of
    the instantiation process, for aggregates whose type has a partial view,
    in Copy_Generic_Node the compiler switches the visibility so that the full
    view of the type is available, and for a type whose full view is a record
    type this leads to incorrectly trying to process the aggregate as a record
    aggregate in Resolve_Aggregate (making a call to Resolve_Record_Aggregate).
    
    Rather than trying to address this by changing what Copy_Generic_Node does,
    this can be fixed by reordering and adjusting the code in Resolve_Aggregate,
    so that we first test whether we need to resolve as a record aggregate
    (if the aggregate is not homogeneous), followed by testing whether the
    type has an Aggregate aspect and calling Resolve_Container_Aggregate.
    As a bonus, we also remove the subsequent complex condition and redundant
    code for handling null container aggregates.
    
    gcc/ada/
    
            * sem_aggr.adb (Resolve_Aggregate): Move condition and call for
            Resolve_Record_Aggregate in front of code related to calling
            Resolve_Container_Aggregate (and add test that the aggregate
            is not homogeneous), and remove special-case testing and call
            to Resolve_Container_Aggregate for empty aggregates.

Diff:
---
 gcc/ada/sem_aggr.adb | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index 658b3a4634c4..6e40e5c25649 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -1182,8 +1182,12 @@ package body Sem_Aggr is
       elsif Is_Array_Type (Typ) and then Null_Record_Present (N) then
          Error_Msg_N ("null record forbidden in array aggregate", N);
 
+      elsif Is_Record_Type (Typ)
+        and then not Is_Homogeneous_Aggregate (N)
+      then
+         Resolve_Record_Aggregate (N, Typ);
+
       elsif Has_Aspect (Typ, Aspect_Aggregate)
-        and then Ekind (Typ) /= E_Record_Type
         and then Ada_Version >= Ada_2022
       then
          --  Check for Ada 2022 and () aggregate.
@@ -1194,22 +1198,6 @@ package body Sem_Aggr is
 
          Resolve_Container_Aggregate (N, Typ);
 
-      --  Check Ada 2022 empty aggregate [] initializing a record type that has
-      --  aspect aggregate; the empty aggregate will be expanded into a call to
-      --  the empty function specified in the aspect aggregate.
-
-      elsif Has_Aspect (Typ, Aspect_Aggregate)
-        and then Ekind (Typ) = E_Record_Type
-        and then Is_Homogeneous_Aggregate (N)
-        and then Is_Empty_List (Expressions (N))
-        and then Is_Empty_List (Component_Associations (N))
-        and then Ada_Version >= Ada_2022
-      then
-         Resolve_Container_Aggregate (N, Typ);
-
-      elsif Is_Record_Type (Typ) then
-         Resolve_Record_Aggregate (N, Typ);
-
       elsif Is_Array_Type (Typ) then
 
          --  First a special test, for the case of a positional aggregate of

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

only message in thread, other threads:[~2024-05-20  7:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-20  7:50 [gcc r15-682] ada: Error on instantiation of generic containing legal container aggregate Marc Poulhi?s

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