From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91282 invoked by alias); 12 Nov 2015 13:25:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 91266 invoked by uid 89); 12 Nov 2015 13:25:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no 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; Thu, 12 Nov 2015 13:25:51 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 1CAC62995E; Thu, 12 Nov 2015 08: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 emN5RzZpYxQN; Thu, 12 Nov 2015 08:25:50 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 0C4C829959; Thu, 12 Nov 2015 08:25:50 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4192) id 084A31A5; Thu, 12 Nov 2015 08:25:50 -0500 (EST) Date: Thu, 12 Nov 2015 13:25:00 -0000 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Spurious visibility error with derivation and incomplete declaration Message-ID: <20151112132550.GA63333@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="qMm9M+Fa2AknHoGS" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-11/txt/msg01512.txt.bz2 --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2368 This patch fixes a spurious visibility error on an operator of a derived type, when the parent type is declared in another unit, and has an incomplete type declaration. The primitive operations of the derived types are to be found in the scope of its base type, and not in that of its ancestor. The following must compile quietly: gnatmake -q operator_use --- with CALC_PACKAGE; with STORE_PACKAGE; with ADA.TEXT_IO; use type CALC_PACKAGE.RECORD_TYPE; procedure OPERATOR_USE is B : CALC_PACKAGE.RECORD_TYPE; begin B := CALC_PACKAGE.GET_VALUE; if STORE_PACKAGE.STORE(4).MY_ACCESS.all.MY_VALUE > B then ADA.TEXT_IO.PUT_LINE("TRUE"); end if; if CALC_PACKAGE.">"(STORE_PACKAGE.STORE(4).MY_ACCESS.all.MY_VALUE, B) then ADA.TEXT_IO.PUT_LINE("TRUE again"); end if; end OPERATOR_USE; --- with TYPE_PACKAGE; package CALC_PACKAGE is type RECORD_TYPE is new TYPE_PACKAGE.BASE_TYPE; function ">" (A : in RECORD_TYPE; B : in RECORD_TYPE) return BOOLEAN; function GET_VALUE return RECORD_TYPE; end CALC_PACKAGE; --- package body CALC_PACKAGE is C_VAL : INTEGER := 0; function GET_VALUE return RECORD_TYPE is begin C_VAL := C_VAL + 1; return (X => C_VAL, Y => 0); end GET_VALUE; function ">" (A : in RECORD_TYPE; B : in RECORD_TYPE) return BOOLEAN is begin return A.X > B.Y; end ">"; end CALC_PACKAGE; --- with CALC_PACKAGE; package STORE_PACKAGE is type INDEX_TYPE is range 1 .. 10; type RECORD_TYPE is record MY_VALUE : CALC_PACKAGE.RECORD_TYPE; end record; type RECORD_ACCESS_TYPE is access all RECORD_TYPE; type STORE_TYPE is record MY_ACCESS : RECORD_ACCESS_TYPE; end record; type ARRAY_TYPE is array (INDEX_TYPE) of STORE_TYPE; STORE : ARRAY_TYPE := (others => (my_access => new Record_Type)); end STORE_PACKAGE; --- package TYPE_PACKAGE is type BASE_TYPE; type BASE_TYPE is record X : INTEGER := 1; Y : INTEGER := 0; end record; end TYPE_PACKAGE; Tested on x86_64-pc-linux-gnu, committed on trunk 2015-11-12 Ed Schonberg * sem_util.adb (Collect_Primitive_Operations): If the type is derived from a type declared elsewhere that has an incomplete type declaration, the primitives are found in the scope of the type nat that of its ancestor. --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=difs Content-length: 663 Index: sem_util.adb =================================================================== --- sem_util.adb (revision 230239) +++ sem_util.adb (working copy) @@ -4223,6 +4223,14 @@ then Id := Defining_Entity (Incomplete_View (Parent (B_Type))); + -- If T is a derived from a type with an incomplete view declared + -- elsewhere, that incomplete view is irrelevant, we want the + -- operations in the scope of T. + + if Scope (Id) /= Scope (B_Type) then + Id := Next_Entity (B_Type); + end if; + else Id := Next_Entity (B_Type); end if; --qMm9M+Fa2AknHoGS--