diff options
author | Bob Duff <duff@adacore.com> | 2023-03-29 13:57:35 -0400 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-05-26 09:29:20 +0200 |
commit | ce081284bde18cf554ac7c10166581c8c667a6b7 (patch) | |
tree | 73d1e6592abae6dd89e6300acab3f6b93285b5a6 /gcc | |
parent | 19668be0f8673a3545b0ad823fe1dd459f2f6772 (diff) | |
download | gcc-ce081284bde18cf554ac7c10166581c8c667a6b7.zip gcc-ce081284bde18cf554ac7c10166581c8c667a6b7.tar.gz gcc-ce081284bde18cf554ac7c10166581c8c667a6b7.tar.bz2 |
ada: Corrections to premature-references rules
This patch corrects the implementation of RM-8.3(17),
which says that a record extension is self-hidden until "record".
Previously, such premature references could cause a compiler crash.
gcc/ada/
* sem_ch3.adb
(Build_Derived_Record_Type): Temporarily set the state of the
Derived_Type to "self-hidden" while processing constraints
and discriminants of a record extension.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/sem_ch3.adb | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index ff52e05..634b1cb 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -9206,10 +9206,14 @@ package body Sem_Ch3 is then -- First, we must analyze the constraint (see comment in point 5.) -- The constraint may come from the subtype indication of the full - -- declaration. + -- declaration. Temporarily set the state of the Derived_Type to + -- "self-hidden" (see RM-8.3(17)). if Constraint_Present then + pragma Assert (Is_Not_Self_Hidden (Derived_Type)); + Set_Is_Not_Self_Hidden (Derived_Type, False); New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic); + Set_Is_Not_Self_Hidden (Derived_Type); -- If there is no explicit constraint, there might be one that is -- inherited from a constrained parent type. In that case verify that @@ -9507,11 +9511,19 @@ package body Sem_Ch3 is if Discriminant_Specs then Set_Has_Unknown_Discriminants (Derived_Type, False); - -- The following call initializes fields Has_Discriminants and - -- Discriminant_Constraint, unless we are processing the completion - -- of a private type declaration. + -- The following call to Check_Or_Process_Discriminants initializes + -- fields Has_Discriminants and Discriminant_Constraint, unless we + -- are processing the completion of a private type declaration. + -- Temporarily set the state of the Derived_Type to "self-hidden" + -- (see RM-8.3(17)), unless it is already the case. - Check_Or_Process_Discriminants (N, Derived_Type); + if Is_Not_Self_Hidden (Derived_Type) then + Set_Is_Not_Self_Hidden (Derived_Type, False); + Check_Or_Process_Discriminants (N, Derived_Type); + Set_Is_Not_Self_Hidden (Derived_Type); + else + Check_Or_Process_Discriminants (N, Derived_Type); + end if; -- For untagged types, the constraint on the Parent_Type must be -- present and is used to rename the discriminants. |