This patch fixes a compiler abort on a discriminant constraint when the
constraint is a subtype indication.
Tested on x86_64-pc-linux-gnu, committed on trunk
2018-05-22 Patrick Bernardi <berna...@adacore.com>
gcc/ada/
* sem_ch3.adb (Build_Discriminant_Constraints): Raise an error if the
user tries to use a subtype indication as a discriminant constraint.
gcc/testsuite/
* gnat.dg/discr50.adb: New testcase.
--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -9877,6 +9877,12 @@ package body Sem_Ch3 is
("a range is not a valid discriminant constraint", Constr);
Discr_Expr (D) := Error;
+ elsif Nkind (Constr) = N_Subtype_Indication then
+ Error_Msg_N
+ ("a subtype indication is not a valid discriminant constraint",
+ Constr);
+ Discr_Expr (D) := Error;
+
else
Process_Discriminant_Expression (Constr, Discr);
Discr_Expr (D) := Constr;
--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/discr50.adb
@@ -0,0 +1,11 @@
+-- { dg-do compile }
+
+procedure Discr50 is
+ type My_Record (D : Integer) is record
+ A : Integer;
+ end record;
+
+ B : My_Record (Positive range 1 .. 10); -- { dg-error "a subtype indication is not a valid discriminant constraint" }
+begin
+ null;
+end Discr50;