[Ada] Spurious error in discriminated aggregate
authorBob Duff <duff@adacore.com>
Wed, 14 Aug 2019 09:51:43 +0000 (09:51 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Wed, 14 Aug 2019 09:51:43 +0000 (09:51 +0000)
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.

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.

From-SVN: r274458

gcc/ada/ChangeLog
gcc/ada/exp_aggr.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/discr57.adb [new file with mode: 0644]

index a36a83a..785d9d8 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-14  Bob Duff  <duff@adacore.com>
+
+       * exp_aggr.adb (Init_Hidden_Discriminants): Avoid processing the
+       wrong discriminant, which could be of the wrong type.
+
 2019-08-14  Eric Botcazou  <ebotcazou@adacore.com>
 
        * sem_ch12.adb (Analyze_Instance_And_Renamings): Do not reset
index 174da6e..6a756fd 100644 (file)
@@ -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
index 89a92fa..dadeb4f 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-14  Bob Duff  <duff@adacore.com>
+
+       * gnat.dg/discr57.adb: New testcase.
+
 2019-08-14  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/generic_inst11.adb, gnat.dg/generic_inst11_pkg.adb,
diff --git a/gcc/testsuite/gnat.dg/discr57.adb b/gcc/testsuite/gnat.dg/discr57.adb
new file mode 100644 (file)
index 0000000..cb5cecc
--- /dev/null
@@ -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;