public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Spurious error in discriminated aggregate
@ 2019-08-14  9:53 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-08-14  9:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: Bob Duff

[-- Attachment #1: Type: text/plain, Size: 419 bytes --]

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 892 bytes --]

--- 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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-14  9:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-14  9:53 [Ada] Spurious error in discriminated aggregate Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).