From patchwork Fri Jan 30 15:25:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 434949 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 21FBA1402AE for ; Sat, 31 Jan 2015 02:27:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=Q7Eas+MSR09LgpM+7OE/q76E/dEWY6GOx2BZoly2jAyxqmIITl bn9pU3vqqHvKgxF1WiysYpt29ovzirfq7j8OlkiiLuJC88Uzxh3M78J8HWpvGK84 q5lDWV/HXOXAltUBl5rA43Hd+3tgz1FQcXKixtX/c2MfDqyQIDokMv/cA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=PkmxLDPOdj72PIzOlFWqrtdgJx8=; b=OEWE3bGlaHkSTN2NxCH4 3oBcl6yjdZkJVAYxASinZTZ4M5NLL6k95wAxltS11kTuMYs8LffFkJYv5njb4VzE KJEyd9yhR3x+wmTDZPAMWXppeVCWBUnVPctKyjg0sbZ4srAxZ6Tp/sEiEPRGOZE6 j8Ry4MyBzWqfKNoT8LJ4bR0= Received: (qmail 23222 invoked by alias); 30 Jan 2015 15:26:05 -0000 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 Received: (qmail 23103 invoked by uid 89); 30 Jan 2015 15:26:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, WEIRD_QUOTING autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 30 Jan 2015 15:25:52 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id C837C11683A; Fri, 30 Jan 2015 10:25:50 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 55fNihEx6LsU; Fri, 30 Jan 2015 10:25:50 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [IPv6:2620:20:4000:0:7a2b:cbff:fe60:cb11]) by rock.gnat.com (Postfix) with ESMTP id B86F011683B; Fri, 30 Jan 2015 10:25:50 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id B77A53FE28; Fri, 30 Jan 2015 10:25:50 -0500 (EST) Date: Fri, 30 Jan 2015 10:25:50 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Obscure ambiguity involving user-defined operators returning Boolean Message-ID: <20150130152550.GA29818@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) This patch fixes a rather obscure bug in case there is a user-defined "+" operator returning Boolean, passed to two contexts where the expected type is Boolean, and the expected type is the result of the PREdefined operator. This is ambiguous, and therefore illegal. gnatmake -q -f cutdown1-main.adb cutdown1-main.adb:4:04: ambiguous expression (cannot resolve "P") cutdown1-main.adb:4:04: possible interpretation at cutdown1.ads:8 cutdown1-main.adb:4:04: possible interpretation at cutdown1.ads:7 gnatmake: "cutdown1-main.adb" compilation error package Cutdown1 is type T1 is range 1 .. 10; -- We have a predefined "+"(T1, T1) --> T1 here that seems to be ignored. function "+" (X, Y : T1) return Boolean; procedure P (X : Boolean); procedure P (X : T1); end Cutdown1; with Ada.Text_IO; use Ada.Text_IO; package body Cutdown1 is function "+" (X, Y : T1) return Boolean is begin Put_Line ("Hello from ""+"""); return False; end "+"; procedure P (X : T1) is begin Put_Line ("Hello from P(T1)"); end P; procedure P (X : Boolean) is begin Put_Line ("Hello from P(Boolean)"); end P; end Cutdown1; with Cutdown1; use Cutdown1; procedure Cutdown1.Main is begin P (T1'(1) + 1); -- ERROR: ambiguous end Cutdown1.Main; Tested on x86_64-pc-linux-gnu, committed on trunk 2015-01-30 Bob Duff * sem_type.adb: sem_type.adb (Remove_Conversions): Need to check both operands of an operator. Index: sem_type.adb =================================================================== --- sem_type.adb (revision 220273) +++ sem_type.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2014, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -1539,6 +1539,8 @@ if Nkind (Act1) in N_Op and then Is_Overloaded (Act1) + and then Nkind_In (Left_Opnd (Act1), N_Integer_Literal, + N_Real_Literal) and then Nkind_In (Right_Opnd (Act1), N_Integer_Literal, N_Real_Literal) and then Has_Compatible_Type (Act1, Standard_Boolean)