From: Arnaud Charlet <charlet@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Ed Schonberg <schonberg@adacore.com>
Subject: [Ada] Interface type conversions are not dynamically tagged
Date: Mon, 05 Sep 2011 14:12:00 -0000 [thread overview]
Message-ID: <20110905141227.GA17140@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 910 bytes --]
A view conversion to an interface type is expanded into a dereference of a
temporary that involves the class-wide interface type. Nevertheless such an
expression is not dynamically tagged, and is not a controlling argument in
a call.
Compiling main.adb must be rejected with:
main.adb:8:10: call to abstract procedure must be dispatching
---
with Types; use Types;
procedure Main is
V : R;
begin
I (V).P1;
I'Class (V).P1;
I (V).P2;
I'Class (V).P2;
end Main;
---
package Types is
type I is interface;
procedure P1 (V : I) is null;
procedure P2 (V : I) is abstract;
type R is new I with null record;
procedure P2 (V : R) is null;
end Types;
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-09-05 Ed Schonberg <schonberg@adacore.com>
* sem_disp.adb (Find_Controlling_Arg): Add checks for
interface type conversions, that are expanded into dereferences.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1188 bytes --]
Index: sem_disp.adb
===================================================================
--- sem_disp.adb (revision 178381)
+++ sem_disp.adb (working copy)
@@ -1616,6 +1616,32 @@
then
return Controlling_Argument (Orig_Node);
+ -- Type conversions are dynamically tagged if the target type, or its
+ -- designated type, are classwide. An interface conversion expands into
+ -- a dereference, so test must be performed on the original node.
+
+ elsif Nkind (Orig_Node) = N_Type_Conversion
+ and then Nkind (N) = N_Explicit_Dereference
+ and then Is_Controlling_Actual (N)
+ then
+ declare
+ Target_Type : constant Entity_Id :=
+ Entity (Subtype_Mark (Orig_Node));
+
+ begin
+ if Is_Class_Wide_Type (Target_Type) then
+ return N;
+
+ elsif Is_Access_Type (Target_Type)
+ and then Is_Class_Wide_Type (Designated_Type (Target_Type))
+ then
+ return N;
+
+ else
+ return Empty;
+ end if;
+ end;
+
-- Normal case
elsif Is_Controlling_Actual (N)
reply other threads:[~2011-09-05 14:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110905141227.GA17140@adacore.com \
--to=charlet@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=schonberg@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).