From: Arnaud Charlet <charlet@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Javier Miranda <miranda@adacore.com>
Subject: [Ada] Missing check on interface primitives
Date: Fri, 31 Oct 2014 11:31:00 -0000 [thread overview]
Message-ID: <20141031112226.GA23052@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 802 bytes --]
The compiler does not not verify always that all the primitives of an
interface type are abstract or null procedures. After this patch the
following test is compiled with errors:
package Pkg is
-- Test 1
type IA is tagged;
function Get_myB (Self : IA) return natural;
type IA is interface;
-- Test 2
type Iface is interface;
function f1 (Obj : Iface) return Natural is (0);
end;
Command: gcc -c pkg.ads
Output:
pkg.ads:4:04: interface function "Get_Myb" must be abstract
pkg.ads:10:04: interface function "F1" must be abstract
Tested on x86_64-pc-linux-gnu, committed on trunk
2014-10-31 Javier Miranda <miranda@adacore.com>
* freeze.adb (Freeze_Record_Type): Add missing
check to verify that all the primitives of an interface type
are abstract or null procedures.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1757 bytes --]
Index: freeze.adb
===================================================================
--- freeze.adb (revision 216963)
+++ freeze.adb (working copy)
@@ -4004,6 +4004,47 @@
-- call to the Analyze_Freeze_Entity for the record type.
end Check_Variant_Part;
+
+ -- Check that all the primitives of an interface type are abstract
+ -- or null procedures.
+
+ if Is_Interface (Rec)
+ and then not Error_Posted (Parent (Rec))
+ then
+ declare
+ Elmt : Elmt_Id;
+ Subp : Entity_Id;
+
+ begin
+ Elmt := First_Elmt (Primitive_Operations (Rec));
+ while Present (Elmt) loop
+ Subp := Node (Elmt);
+
+ if not Is_Abstract_Subprogram (Subp)
+
+ -- Avoid reporting the error on inherited primitives
+
+ and then Comes_From_Source (Subp)
+ then
+ Error_Msg_Name_1 := Chars (Subp);
+
+ if Ekind (Subp) = E_Procedure then
+ if not Null_Present (Parent (Subp)) then
+ Error_Msg_N
+ ("interface procedure % must be abstract or null",
+ Parent (Subp));
+ end if;
+ else
+ Error_Msg_N
+ ("interface function % must be abstract",
+ Parent (Subp));
+ end if;
+ end if;
+
+ Next_Elmt (Elmt);
+ end loop;
+ end;
+ end if;
end Freeze_Record_Type;
-------------------------------
reply other threads:[~2014-10-31 11:22 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=20141031112226.GA23052@adacore.com \
--to=charlet@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=miranda@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).