aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorJavier Miranda <miranda@adacore.com>2019-07-09 07:54:45 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-07-09 07:54:45 +0000
commitc7854dbd0fedde0bb15e56cc9b4f120d80f3ef41 (patch)
tree91b19dfd69b6241254c3016b24f4b857e88b0942 /gcc/ada
parent134f52b9c4f45076efe6a3c345e6e01e95998cc1 (diff)
downloadgcc-c7854dbd0fedde0bb15e56cc9b4f120d80f3ef41.zip
gcc-c7854dbd0fedde0bb15e56cc9b4f120d80f3ef41.tar.gz
gcc-c7854dbd0fedde0bb15e56cc9b4f120d80f3ef41.tar.bz2
[Ada] Missing error on generic type with representation clause
The compiler does not report an error on a generic type that has a representation clause when its ultimate parent is not a generic formal. 2019-07-09 Javier Miranda <miranda@adacore.com> gcc/ada/ * sem_ch13.adb (Rep_Item_Too_Early): Representation clauses are not allowed for a derivation of a generic type. Extend the current test to check that none of the parents is a generic type. gcc/testsuite/ * gnat.dg/rep_clause8.adb: New testcase. From-SVN: r273283
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog7
-rw-r--r--gcc/ada/sem_ch13.adb20
2 files changed, 26 insertions, 1 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 7d8ea33..d8f7de6 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,10 @@
+2019-07-09 Javier Miranda <miranda@adacore.com>
+
+ * sem_ch13.adb (Rep_Item_Too_Early): Representation clauses are
+ not allowed for a derivation of a generic type. Extend the
+ current test to check that none of the parents is a generic
+ type.
+
2019-07-09 Hristian Kirtchev <kirtchev@adacore.com>
* exp_ch9.adb, exp_util.adb, repinfo.adb, sem_ch12.adb,
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index cbae9c8..6e52272 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -12548,6 +12548,24 @@ package body Sem_Ch13 is
------------------------
function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
+ function Has_Generic_Parent (E : Entity_Id) return Boolean;
+ -- Return True if any ancestor is a generic type
+
+ function Has_Generic_Parent (E : Entity_Id) return Boolean is
+ Ancestor_Type : Entity_Id := Etype (E);
+
+ begin
+ while Present (Ancestor_Type)
+ and then not Is_Generic_Type (Ancestor_Type)
+ and then Etype (Ancestor_Type) /= Ancestor_Type
+ loop
+ Ancestor_Type := Etype (Ancestor_Type);
+ end loop;
+
+ return Present (Ancestor_Type)
+ and then Is_Generic_Type (Ancestor_Type);
+ end Has_Generic_Parent;
+
begin
-- Cannot apply non-operational rep items to generic types
@@ -12555,7 +12573,7 @@ package body Sem_Ch13 is
return False;
elsif Is_Type (T)
- and then Is_Generic_Type (Root_Type (T))
+ and then Has_Generic_Parent (T)
and then (Nkind (N) /= N_Pragma
or else Get_Pragma_Id (N) /= Pragma_Convention)
then