This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] ada/35792: Refuse completion of tagged type by task type or protected type
On 9/04, Arnaud Charlet wrote:
| > As for the branch, I thought it was necessarily for trunk unless
| > specified otherwise, but ok, let's make it clear.
|
| Specifiying how/where you tested it is also useful. Also please note that
| x86-linux is too generic, since there are differences between i586-linux
| and i686-linux for instance.
I doubt that semantic front-end issues are platform dependent.
| Howewer, the patch is incomplete and too strict: a protected type or a task
| type that implements an interface is a tagged type. The proper check would
| be something like:
Ok to check it on trunk with your additional test for interfaces (and
both attributions) and a more complete test case?
If an incomplete_type_declaration includes the reserved word tagged,
then a full_type_declaration that completes it shall declare a tagged
type.
Without this patch, GNAT detects the error only on T3 (see testcase)
and forgets T1 and T2 full type declarations. Those cases (task type and
protected type) were kept out at the wrong place.
With this patch, GNAT correctly issues:
7. protected type T1 is end T1;
|
>>> full declaration of type "T1" defined at line 4 must be a tagged type
8. task type T2;
|
>>> full declaration of type "T2" defined at line 5 must be a tagged type
9. type T3 is null record;
|
>>> full declaration of type "T3" defined at line 6 must be tagged
Tested on Linux/x86.
Ok for trunk?
gcc/ada/
PR ada/35792
* sem_ch3.adb (Find_Type_Name): Refuse completion of tagged type
by a task type or a protected type.
gcc/testsuite/
PR ada/35792
* gnat.dg/specs/tag2.ads: New.
---
gcc/ada/sem_ch3.adb | 17 ++++++++++++-----
gcc/testsuite/gnat.dg/specs/tag2.ads | 17 +++++++++++++++++
2 files changed, 29 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gnat.dg/specs/tag2.ads
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 2bd3a4c..fa4eebc 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -13046,13 +13046,20 @@ package body Sem_Ch3 is
if Is_Type (Prev)
and then (Is_Tagged_Type (Prev)
or else Present (Class_Wide_Type (Prev)))
- and then not Nkind_In (N, N_Task_Type_Declaration,
- N_Protected_Type_Declaration)
then
- -- The full declaration is either a tagged record or an
- -- extension otherwise this is an error
+ -- The full declaration is either a tagged record, an
+ -- extension, or a task type or protected type implementing
+ -- an interface, otherwise this is an error.
- if Nkind (Type_Definition (N)) = N_Record_Definition then
+ if Nkind_In (N, N_Task_Type_Declaration,
+ N_Protected_Type_Declaration)
+ then
+ if No (Interface_List (N)) then
+ Error_Msg_NE
+ ("full declaration of } must be a tagged type ", Id, Prev);
+ end if;
+
+ elsif Nkind (Type_Definition (N)) = N_Record_Definition then
if not Tagged_Present (Type_Definition (N)) then
Error_Msg_NE
("full declaration of } must be tagged", Id, Prev);
diff --git a/gcc/testsuite/gnat.dg/specs/tag2.ads b/gcc/testsuite/gnat.dg/specs/tag2.ads
new file mode 100644
index 0000000..8e09f25
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/specs/tag2.ads
@@ -0,0 +1,17 @@
+-- { dg-do compile }
+
+package tag2 is
+ type I is synchronized interface;
+ type T1 is tagged;
+ type T2 is tagged;
+ type T3 is tagged;
+ type T4 is tagged;
+ type T5 is tagged;
+ type T6 is tagged;
+ protected type T1 is end T1; -- { dg-error "must be a tagged type" }
+ task type T2; -- { dg-error "must be a tagged type" }
+ type T3 is null record; -- { dg-error "must be tagged" }
+ task type T4 is new I with end;
+ protected type T5 is new I with end;
+ type T6 is tagged null record;
+end tag2;