From patchwork Tue Jun 22 08:44:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 56414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2749FB6F0C for ; Tue, 22 Jun 2010 18:44:28 +1000 (EST) Received: (qmail 27913 invoked by alias); 22 Jun 2010 08:44:20 -0000 Received: (qmail 27890 invoked by uid 22791); 22 Jun 2010 08:44:18 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Jun 2010 08:44:13 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 4B1D1CB024F; Tue, 22 Jun 2010 10:44:15 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id S2Q1GnkroiKP; Tue, 22 Jun 2010 10:44:15 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id 31A69CB022F; Tue, 22 Jun 2010 10:44:15 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 1D793D9B31; Tue, 22 Jun 2010 10:44:15 +0200 (CEST) Date: Tue, 22 Jun 2010 10:44:15 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Further illegalities with operator call in functional notation Message-ID: <20100622084415.GA29927@adacore.com> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 * sem_res.adb (Make_Call_Into_Operator): Diagnose an incorrect scope for an operator in a functional notation, when operands are universal. 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;