diff options
author | Bob Duff <duff@adacore.com> | 2024-10-09 07:25:14 -0400 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2024-11-04 16:57:55 +0100 |
commit | e2f073947a324bbfee866d9282bb778ddead95f4 (patch) | |
tree | 3761ed6bc89a6c1890ad1dbd06de34e298ab01c8 /gcc/ada | |
parent | 74cdc0d576479756c7faa88f74b041cd9ff51636 (diff) | |
download | gcc-e2f073947a324bbfee866d9282bb778ddead95f4.zip gcc-e2f073947a324bbfee866d9282bb778ddead95f4.tar.gz gcc-e2f073947a324bbfee866d9282bb778ddead95f4.tar.bz2 |
ada: Correction to disable self-referential with_clauses
Follow-on to previous change "Disable self-referential with_clauses",
which caused some regressions. Remove useless use clauses referring
to useless self-referential with'ed packages. This is necessary
because in some cases, such use clauses cause the compiler to
crash or give spurious errors.
In addition, enable the warning on self-referential with_clauses.
gcc/ada/ChangeLog:
* sem_ch10.adb (Analyze_With_Clause): In the case of a
self-referential with clause, if there is a subsequent use clause
for the same package (which is necessarily useless), remove it from
the context clause. Reenable the warning.
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/sem_ch10.adb | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb index 202a44e..4e58244 100644 --- a/gcc/ada/sem_ch10.adb +++ b/gcc/ada/sem_ch10.adb @@ -3039,11 +3039,32 @@ package body Sem_Ch10 is -- Self-referential withs are always useless, so warn - if Warn_On_Redundant_Constructs and then False then -- ??? - -- Disable for now, because it breaks SPARK builds + if Warn_On_Redundant_Constructs then Error_Msg_N ("unnecessary with of self?r?", N); end if; + declare + This : Node_Id := Next (N); + begin + -- Remove subsequent use clauses for the same package + + while Present (This) loop + declare + Nxt : constant Node_Id := Next (This); + begin + if Nkind (This) = N_Use_Package_Clause + and then Same_Name (Name (N), Name (This)) + then + if not More_Ids (This) and not Prev_Ids (This) then + Remove (This); + end if; + end if; + + This := Nxt; + end; + end loop; + end; + -- Normal (non-self-referential) case else |