From: Arnaud Charlet <charlet@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Ed Schonberg <schonberg@adacore.com>
Subject: [Ada] Further illegalities with operator call in functional notation
Date: Tue, 22 Jun 2010 09:08:00 -0000 [thread overview]
Message-ID: <20100622084415.GA29927@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 750 bytes --]
With this patch the compiler properly rejects a call of the form P."+" (X, Y)
when X and Y are numeric literals, and the result type is not declared in P.
Compiling the following must be rejected with:
derived_folded_mistyped.adb:8:27: expect type "T3"
---
procedure Derived_Folded_Mistyped is
package Scop is
type T2 is range 1 .. 4;
end Scop;
type T3 is new Scop.T2;
X : constant T3 := Scop."+" (1, 2); -- ERROR: Scop."+" returns T2
begin
null;
end Derived_Folded_Mistyped;
Tested on x86_64-pc-linux-gnu, committed on trunk
2010-06-22 Ed Schonberg <schonberg@adacore.com>
* sem_res.adb (Make_Call_Into_Operator): Diagnose an incorrect scope
for an operator in a functional notation, when operands are universal.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1345 bytes --]
Index: sem_res.adb
===================================================================
--- sem_res.adb (revision 161144)
+++ sem_res.adb (working copy)
@@ -1422,6 +1422,31 @@ package body Sem_Res is
("& not declared in&", N, Selector_Name (Name (N)));
Set_Etype (N, Any_Type);
return;
+
+ -- Detect a mismatch between the context type and the result type
+ -- in the named package, which is otherwise not detected if the
+ -- operands are universal. Check is only needed if source entity is
+ -- an operator, not a function that renames an operator.
+
+ elsif Nkind (Parent (N)) /= N_Type_Conversion
+ and then Ekind (Entity (Name (N))) = E_Operator
+ and then Is_Numeric_Type (Typ)
+ and then not Is_Universal_Numeric_Type (Typ)
+ and then Scope (Base_Type (Typ)) /= Pack
+ and then not In_Instance
+ then
+ if Is_Fixed_Point_Type (Typ)
+ and then (Op_Name = Name_Op_Multiply
+ or else
+ Op_Name = Name_Op_Divide)
+ then
+ -- Already checked above
+
+ null;
+
+ else
+ Error_Msg_NE ("expect type&", N, Typ);
+ end if;
end if;
end if;
reply other threads:[~2010-06-22 8:44 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=20100622084415.GA29927@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).