* [PATCH] ada/29015: Do not ICE on incomplete type whose underlying type is known
@ 2008-04-09 22:02 Samuel Tardieu
2008-04-16 14:53 ` Arnaud Charlet
0 siblings, 1 reply; 2+ messages in thread
From: Samuel Tardieu @ 2008-04-09 22:02 UTC (permalink / raw)
To: gcc-patches
When an incomplete type is used in an instantiation, GNAT correctly
rejects it if its use is premature. However, if the Underlying_Type is
present, GNAT assumes that the use is not premature and tries to use
the type Full_View unconditionally.
In some cases, the Underlying_Type may be known even if the type is
incomplete. In the following example, compiling incomplete2.adb will
analyze incomplete1.ads. In incomplete2.ads, there is only a "limited
with" on Incomplete1. At G instantiation time, the type Incomplete1.T
has no Full_View but its Underlying_Type is known.
This patch checks the full view instead of the underlying type, giving
the following error message:
% gcc -c -gnatv incomplete2.adb
==============Error messages for source file: incomplete2.ads
7. package I1 is new G (Incomplete1.T);
|
>>> premature use of incomplete type
>>> instantiation abandoned
instead of a bug box.
Regtested on i686-pc-linux-gnu.
Ok for trunk?
gcc/ada/
PR ada/29015
* sem_ch12.adb (Instantiate_Type): Check whether the full view of
the type is known instead of the underlying type.
gcc/testsuite/
PR ada/29015
* gnat.dg/incomplete1.ads, gnat.dg/incomplete2.ads,
gnat.dg/incomplete2.adb: New.
---
gcc/ada/sem_ch12.adb | 2 +-
gcc/testsuite/gnat.dg/incomplete1.ads | 3 +++
gcc/testsuite/gnat.dg/incomplete2.adb | 4 ++++
gcc/testsuite/gnat.dg/incomplete2.ads | 8 ++++++++
4 files changed, 16 insertions(+), 1 deletions(-)
create mode 100644 gcc/testsuite/gnat.dg/incomplete1.ads
create mode 100644 gcc/testsuite/gnat.dg/incomplete2.adb
create mode 100644 gcc/testsuite/gnat.dg/incomplete2.ads
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 00c9f39..b22af91 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -9980,7 +9980,7 @@ package body Sem_Ch12 is
Ekind (Root_Type (Act_T)) = E_Incomplete_Type)
then
if Is_Class_Wide_Type (Act_T)
- or else No (Underlying_Type (Act_T))
+ or else No (Full_View (Act_T))
then
Error_Msg_N ("premature use of incomplete type", Actual);
Abandon_Instantiation (Actual);
diff --git a/gcc/testsuite/gnat.dg/incomplete1.ads b/gcc/testsuite/gnat.dg/incomplete1.ads
new file mode 100644
index 0000000..3490033
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/incomplete1.ads
@@ -0,0 +1,3 @@
+package Incomplete1 is
+ type T is null record;
+end Incomplete1;
diff --git a/gcc/testsuite/gnat.dg/incomplete2.adb b/gcc/testsuite/gnat.dg/incomplete2.adb
new file mode 100644
index 0000000..19c8360
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/incomplete2.adb
@@ -0,0 +1,4 @@
+-- { dg-do compile }
+-- { dg-excess-errors "instantiation abandoned" }
+with Incomplete1;
+package body Incomplete2 is end Incomplete2;
diff --git a/gcc/testsuite/gnat.dg/incomplete2.ads b/gcc/testsuite/gnat.dg/incomplete2.ads
new file mode 100644
index 0000000..21f2d2b
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/incomplete2.ads
@@ -0,0 +1,8 @@
+limited with Incomplete1;
+package Incomplete2 is
+ pragma Elaborate_Body;
+ generic
+ type T is private;
+ package G is end G;
+ package I1 is new G (Incomplete1.T); -- { dg-error "premature use" }
+end Incomplete2;
--
1.5.4.5
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ada/29015: Do not ICE on incomplete type whose underlying type is known
2008-04-09 22:02 [PATCH] ada/29015: Do not ICE on incomplete type whose underlying type is known Samuel Tardieu
@ 2008-04-16 14:53 ` Arnaud Charlet
0 siblings, 0 replies; 2+ messages in thread
From: Arnaud Charlet @ 2008-04-16 14:53 UTC (permalink / raw)
To: Samuel Tardieu; +Cc: gcc-patches, Ed Schonberg
> Ok for trunk?
>
> gcc/ada/
> PR ada/29015
> * sem_ch12.adb (Instantiate_Type): Check whether the full view of
> the type is known instead of the underlying type.
>
> gcc/testsuite/
> PR ada/29015
> * gnat.dg/incomplete1.ads, gnat.dg/incomplete2.ads,
> gnat.dg/incomplete2.adb: New.
This patch is OK.
Arno
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-04-16 12:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-09 22:02 [PATCH] ada/29015: Do not ICE on incomplete type whose underlying type is known Samuel Tardieu
2008-04-16 14:53 ` Arnaud Charlet
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).