aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch12.adb
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2024-04-01 14:05:14 -0400
committerMarc Poulhiès <poulhies@adacore.com>2024-05-20 09:47:06 +0200
commitb3cfe6e88ffcc636d83e4ac5708065c3131e1766 (patch)
tree5fc61bea87459d131e3e49dc2a2ce84d1aa015b1 /gcc/ada/sem_ch12.adb
parent49eb34ea61c6e8fbb10d3a36484cbf5468580fba (diff)
downloadgcc-b3cfe6e88ffcc636d83e4ac5708065c3131e1766.zip
gcc-b3cfe6e88ffcc636d83e4ac5708065c3131e1766.tar.gz
gcc-b3cfe6e88ffcc636d83e4ac5708065c3131e1766.tar.bz2
ada: Allow 'others' in formal packages with overloaded formals
If a generic package has two or more generic formal parameters with the same defining name (which can happen only for formal subprograms), then RM-12.7(4.1/3) disallows named associations in a corresponding formal package. This is not intended to cover "others => <>". This patch allows "others => <>" even when it applies to such formals. Previously, the compiler incorrectly gave an error. Minor related cleanups involving type Text_Ptr. gcc/ada/ * sem_ch12.adb: Misc cleanups and comment fixes. (Check_Overloaded_Formal_Subprogram): Remove the Others_Choice error message. (Others_Choice): Remove this variable; no longer needed. * types.ads (Text_Ptr): Add a range constraint limiting the subtype to values that are actually used. This has the advantage that when the compiler is compiled with validity checks, uninitialized values of subtypes Text_Ptr and Source_Ptr will be caught. * sinput.ads (Sloc_Adjust): Use the base subtype; this is used as an offset, so we need to allow arbitrary negative values.
Diffstat (limited to 'gcc/ada/sem_ch12.adb')
-rw-r--r--gcc/ada/sem_ch12.adb27
1 files changed, 10 insertions, 17 deletions
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 4ceddda..9919cda 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -1130,10 +1130,11 @@ package body Sem_Ch12 is
Saved_Formal : Node_Id;
Default_Formals : constant List_Id := New_List;
- -- If an Others_Choice is present, some of the formals may be defaulted.
- -- To simplify the treatment of visibility in an instance, we introduce
- -- individual defaults for each such formal. These defaults are
- -- appended to the list of associations and replace the Others_Choice.
+ -- If an N_Others_Choice is present, some of the formals may be
+ -- defaulted. To simplify the treatment of visibility in an instance,
+ -- we introduce individual defaults for each such formal. These
+ -- defaults are appended to the list of associations and replace the
+ -- N_Others_Choice.
Found_Assoc : Node_Id;
-- Association for the current formal being match. Empty if there are
@@ -1145,9 +1146,8 @@ package body Sem_Ch12 is
Num_Actuals : Nat := 0;
Others_Present : Boolean := False;
- Others_Choice : Node_Id := Empty;
-- In Ada 2005, indicates partial parameterization of a formal
- -- package. As usual an other association must be last in the list.
+ -- package. As usual an 'others' association must be last in the list.
procedure Build_Subprogram_Wrappers;
-- Ada 2022: AI12-0272 introduces pre/postconditions for formal
@@ -1195,7 +1195,7 @@ package body Sem_Ch12 is
procedure Process_Default (Formal : Node_Id);
-- Add a copy of the declaration of a generic formal to the list of
-- associations, and add an explicit box association for its entity
- -- if there is none yet, and the default comes from an Others_Choice.
+ -- if there is none yet, and the default comes from an N_Others_Choice.
function Renames_Standard_Subprogram (Subp : Entity_Id) return Boolean;
-- Determine whether Subp renames one of the subprograms defined in the
@@ -1314,14 +1314,8 @@ package body Sem_Ch12 is
Error_Msg_N
("named association not allowed for overloaded formal",
Found_Assoc);
-
- else
- Error_Msg_N
- ("named association not allowed for overloaded formal",
- Others_Choice);
+ Abandon_Instantiation (Instantiation_Node);
end if;
-
- Abandon_Instantiation (Instantiation_Node);
end if;
Next (Temp_Formal);
@@ -1592,7 +1586,7 @@ package body Sem_Ch12 is
Append (Decl, Assoc_List);
- if No (Found_Assoc) then
+ if No (Found_Assoc) then -- i.e. 'others'
Default :=
Make_Generic_Association (Loc,
Selector_Name =>
@@ -1686,7 +1680,6 @@ package body Sem_Ch12 is
while Present (Actual) loop
if Nkind (Actual) = N_Others_Choice then
Others_Present := True;
- Others_Choice := Actual;
if Present (Next (Actual)) then
Error_Msg_N ("OTHERS must be last association", Actual);
@@ -2311,7 +2304,7 @@ package body Sem_Ch12 is
-- If this is a formal package, normalize the parameter list by adding
-- explicit box associations for the formals that are covered by an
- -- Others_Choice.
+ -- N_Others_Choice.
Append_List (Default_Formals, Formals);