From patchwork Mon Aug 29 13:31:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 112049 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 CC9ADB6F95 for ; Mon, 29 Aug 2011 23:31:52 +1000 (EST) Received: (qmail 15606 invoked by alias); 29 Aug 2011 13:31:49 -0000 Received: (qmail 15590 invoked by uid 22791); 29 Aug 2011 13:31:48 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 29 Aug 2011 13:31:23 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id BB48C2BB13A; Mon, 29 Aug 2011 09:31:22 -0400 (EDT) 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 cyKqtVVNPrtm; Mon, 29 Aug 2011 09:31:22 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id A6FBE2BB137; Mon, 29 Aug 2011 09:31:22 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id A5C1792A55; Mon, 29 Aug 2011 09:31:22 -0400 (EDT) Date: Mon, 29 Aug 2011 09:31:22 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Resolving spurious ambiguities within instantiations Message-ID: <20110829133122.GA29653@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 The expanded code for an instantiation may contain apparent ambiguities when two subprograms that are generic formals or that depend on formal types become homonyms after formals are replaced with actuals. In some cases, the ambiguity can be resolved by favoring the innermost interpretation, when both of them are declared within the instance. No small example available. Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-29 Ed Schonberg * sem_ch8.adb (Find_Renamed_Entity): Within an instance, use scope depth of candidates to resolve a potentially spurious ambiguity between two visible subprograms. Index: sem_ch8.adb =================================================================== --- sem_ch8.adb (revision 178191) +++ sem_ch8.adb (working copy) @@ -4841,7 +4841,9 @@ Set_Entity_Or_Discriminal (N, E); if Ada_Version >= Ada_2012 - and then Nkind (Parent (N)) in N_Subexpr + and then + (Nkind (Parent (N)) in N_Subexpr + or else Nkind (Parent (N)) = N_Object_Declaration) then Check_Implicit_Dereference (N, Etype (E)); end if; @@ -5531,13 +5533,30 @@ if Present (Inst) then if Within (It.Nam, Inst) then - return (It.Nam); + if Within (Old_S, Inst) then + + -- Choose the innermost subprogram, which would + -- have hidden the outer one in the generic. + + if Scope_Depth (It.Nam) < + Scope_Depth (Old_S) + then + return Old_S; + + else + return It.Nam; + end if; + end if; + elsif Within (Old_S, Inst) then return (Old_S); + else return Report_Overload; end if; + -- If not within an instance, ambiguity is real. + else return Report_Overload; end if;