From patchwork Mon Jun 14 13:33:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] overriding indicator in subunit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 55530 Message-Id: <20100614133306.GA11539@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Robert A Duff Date: Mon, 14 Jun 2010 15:33:06 +0200 From: Arnaud Charlet List-Id: The parser did not correctly recognize "overriding" and "not overriding" in a subunit. The following test should compile silently. package Subunits is type T is null record; not overriding procedure Not_Overriding (X : T); end Subunits; package body Subunits is not overriding procedure Not_Overriding (X : T) is separate; end Subunits; separate (Subunits) not overriding procedure Not_Overriding (X : T) is begin null; end Not_Overriding; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-14 Bob Duff * par-ch10.adb (P_Subunit): If the next token after "separate(X)" is Tok_Not or Tok_Overriding, call P_Subprogram. We had previously given the incorrect error "proper body expected". * par-ch6.adb (P_Subprogram): Suppress "overriding indicator not allowed here" error in case of subunits, which was triggered by the above change to P_Subunit. Index: par-ch6.adb =================================================================== --- par-ch6.adb (revision 160705) +++ par-ch6.adb (working copy) @@ -215,14 +215,17 @@ package body Ch6 is -- already been given, so no need to give another message here. -- An overriding indicator is allowed for subprogram declarations, - -- bodies, renamings, stubs, and instantiations. The test against - -- Pf_Decl_Pbod is added to account for the case of subprograms - -- declared in a protected type, where only subprogram declarations - -- and bodies can occur. + -- bodies (including subunits), renamings, stubs, and + -- instantiations. The test against Pf_Decl_Pbod is added to account + -- for the case of subprograms declared in a protected type, where + -- only subprogram declarations and bodies can occur. The Pf_Pbod + -- case is for subunits. if Pf_Flags /= Pf_Decl_Gins_Pbod_Rnam_Stub and then Pf_Flags /= Pf_Decl_Pbod + and then + Pf_Flags /= Pf_Pbod then Error_Msg_SC ("overriding indicator not allowed here!"); Index: par-ch10.adb =================================================================== --- par-ch10.adb (revision 160705) +++ par-ch10.adb (working copy) @@ -1028,7 +1028,11 @@ package body Ch10 is Ignore (Tok_Semicolon); - if Token = Tok_Function or else Token = Tok_Procedure then + if Token = Tok_Function + or else Token = Tok_Not + or else Token = Tok_Overriding + or else Token = Tok_Procedure + then Body_Node := P_Subprogram (Pf_Pbod); elsif Token = Tok_Package then