From patchwork Mon Aug 19 08:39:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1149108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-507221-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jlRnoepJ"; dkim-atps=neutral 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 46BnS539QXz9s3Z for ; Mon, 19 Aug 2019 18:40:21 +1000 (AEST) 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=EYhYtjmr4XbC1xXDWn5/+sITKS9LoeNgwqzYmQycbxWOqX++S1 T9apNenE2KPrzW7vdM45n53A0cJ9klmfgy3A/kDeGQOQV8DXMfR0gNK+xf7DD4J7 i+BB5FNdRcy8jumhXHxUbrj4zmKlbWf/7A2ccc77z411muMTLL+RmIseY= 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=sD42tSGa/+RqIgLOnjUxifsTZH0=; b=jlRnoepJviGkx6IBrwJY +sIPavi0kaYRYN/D7eEhabwlRxfbK+xqzd4e4ohM2sY3tnaAuhlt5ymBqXiNC9iH T6dZlVbRg23Klb70K8bBD85YJBCZ9hdf/0JfPvwU0kfhR/r6qsBpS2eJ+4nApK3R 8rhOfU5PwTtzFDRvhQL3Uq4= Received: (qmail 115561 invoked by alias); 19 Aug 2019 08:39:06 -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 115518 invoked by uid 89); 19 Aug 2019 08:39:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= 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 ESMTP; Mon, 19 Aug 2019 08:39:05 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id EAA1056050; Mon, 19 Aug 2019 04:39:01 -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 GI2kPbejQRmA; Mon, 19 Aug 2019 04:39:01 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id D994F11619A; Mon, 19 Aug 2019 04:39:01 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id D89586AB; Mon, 19 Aug 2019 04:39:01 -0400 (EDT) Date: Mon, 19 Aug 2019 04:39:01 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Legality of protected subp. implementing interface operations Message-ID: <20190819083901.GA33486@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This patch refines the predicate that implements rule in RM 9.4 (11.9/2) Compiling b94.ads must yield: b94.ads:11:17: illegal overriding of subprogram inherited from interface b94.ads:11:17: first formal of "N" declared at line 8 must be of mode "out", "in out" or access-to-variable ---- package B94 is type Prot2_Int is protected interface; procedure J (PI : in Prot2_Int; N : in Integer) is null; procedure K (PI : in out Prot2_Int; N : in Integer) is null; procedure L (PI : out Prot2_Int; N : in Integer) is null; procedure M (PI : access Prot2_Int; N : in Integer) is null; procedure N (PI : access constant Prot2_Int; N : in Integer) is null; protected type Protected_2 is new Prot2_Int with procedure N (N : in Integer); -- ERROR: {7;1} end Protected_2; end B94; Tested on x86_64-pc-linux-gnu, committed on trunk 2019-08-19 Ed Schonberg gcc/ada/ * sem_ch6.adb (Check_Synchronized_Overriding): Complete predicate that applies legality check in 9.4 (11.9/2): if an inherited subprogram is implemented by a protected procedure or entry, its first paarameter must be out, in_out or access_to_varible. --- gcc/ada/sem_ch6.adb +++ gcc/ada/sem_ch6.adb @@ -7034,6 +7034,11 @@ package body Sem_Ch6 is In_Scope : Boolean; Typ : Entity_Id; + function Is_Valid_Formal (F : Entity_Id) return Boolean; + -- Predicate for legality rule in 9.4 (11.9/2): If an inherited + -- subprogram is implemented by a protected procedure or entry, + -- its first parameter must be out, in out, or access-to-variable. + function Matches_Prefixed_View_Profile (Prim_Params : List_Id; Iface_Params : List_Id) return Boolean; @@ -7042,6 +7047,19 @@ package body Sem_Ch6 is -- Iface_Params. Also determine if the type of first parameter of -- Iface_Params is an implemented interface. + ---------------------- + -- Is_Valid_Formal -- + ---------------------- + + function Is_Valid_Formal (F : Entity_Id) return Boolean is + begin + return + Ekind_In (F, E_In_Out_Parameter, E_Out_Parameter) + or else + (Nkind (Parameter_Type (Parent (F))) = N_Access_Definition + and then not Constant_Present (Parameter_Type (Parent (F)))); + end Is_Valid_Formal; + ----------------------------------- -- Matches_Prefixed_View_Profile -- ----------------------------------- @@ -7295,10 +7313,7 @@ package body Sem_Ch6 is if Ekind_In (Candidate, E_Entry, E_Procedure) and then Is_Protected_Type (Typ) - and then Ekind (Formal) /= E_In_Out_Parameter - and then Ekind (Formal) /= E_Out_Parameter - and then Nkind (Parameter_Type (Parent (Formal))) /= - N_Access_Definition + and then not Is_Valid_Formal (Formal) then null;