summaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch5.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/sem_ch5.adb')
-rw-r--r--gcc/ada/sem_ch5.adb50
1 files changed, 50 insertions, 0 deletions
diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index f756dbcaf5d..b062be948a1 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -2626,6 +2626,56 @@ package body Sem_Ch5 is
Push_Scope (Ent);
Analyze_Iteration_Scheme (Iter);
+ -- Check for following case which merits a warning if the type E of is
+ -- a multi-dimensional array (and no explicit subscript ranges present).
+
+ -- for J in E'Range
+ -- for K in E'Range
+
+ if Present (Iter)
+ and then Present (Loop_Parameter_Specification (Iter))
+ then
+ declare
+ LPS : constant Node_Id := Loop_Parameter_Specification (Iter);
+ DSD : constant Node_Id :=
+ Original_Node (Discrete_Subtype_Definition (LPS));
+ begin
+ if Nkind (DSD) = N_Attribute_Reference
+ and then Attribute_Name (DSD) = Name_Range
+ and then No (Expressions (DSD))
+ then
+ declare
+ Typ : constant Entity_Id := Etype (Prefix (DSD));
+ begin
+ if Is_Array_Type (Typ)
+ and then Number_Dimensions (Typ) > 1
+ and then Nkind (Parent (N)) = N_Loop_Statement
+ and then Present (Iteration_Scheme (Parent (N)))
+ then
+ declare
+ OIter : constant Node_Id :=
+ Iteration_Scheme (Parent (N));
+ OLPS : constant Node_Id :=
+ Loop_Parameter_Specification (OIter);
+ ODSD : constant Node_Id :=
+ Original_Node (Discrete_Subtype_Definition (OLPS));
+ begin
+ if Nkind (ODSD) = N_Attribute_Reference
+ and then Attribute_Name (ODSD) = Name_Range
+ and then No (Expressions (ODSD))
+ and then Etype (Prefix (ODSD)) = Typ
+ then
+ Error_Msg_Sloc := Sloc (ODSD);
+ Error_Msg_N
+ ("inner range same as outer range#?", DSD);
+ end if;
+ end;
+ end if;
+ end;
+ end if;
+ end;
+ end if;
+
-- Analyze the statements of the body except in the case of an Ada 2012
-- iterator with the expander active. In this case the expander will do
-- a rewrite of the loop into a while loop. We will then analyze the