[Ada] Spurious error in discriminated aggregate
diff mbox series

Message ID 20190814095312.GA52210@adacore.com
State New
Headers show
Series
  • [Ada] Spurious error in discriminated aggregate
Related show

Commit Message

Pierre-Marie de Rodat Aug. 14, 2019, 9:53 a.m. UTC
This patch fixes a bug in which a spurious error is given on an
aggregate of a type derived from a subtype with a constrained
discriminant.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-14  Bob Duff  <duff@adacore.com>

gcc/ada/

	* exp_aggr.adb (Init_Hidden_Discriminants): Avoid processing the
	wrong discriminant, which could be of the wrong type.

gcc/testsuite/

	* gnat.dg/discr57.adb: New testcase.

Patch
diff mbox series

--- gcc/ada/exp_aggr.adb
+++ gcc/ada/exp_aggr.adb
@@ -2689,8 +2689,10 @@  package body Exp_Aggr is
                Discr_Constr :=
                  First_Elmt (Stored_Constraint (Full_View (Base_Typ)));
 
+            --  Otherwise, no discriminant to process
+
             else
-               Discr_Constr := First_Elmt (Stored_Constraint (Typ));
+               Discr_Constr := No_Elmt;
             end if;
 
             while Present (Discr) and then Present (Discr_Constr) loop

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/discr57.adb
@@ -0,0 +1,17 @@ 
+--  { dg-do compile }
+
+procedure Discr57 is
+
+   type T1(Scalar : Boolean) is abstract tagged null record;
+
+   subtype S1 is T1 (Scalar => False);
+
+   type T2(Lower_Bound : Natural) is new
+     S1 with null record;
+
+   Obj : constant T2 :=
+       (Lower_Bound => 123);
+
+begin
+   null;
+end Discr57;