From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 2627E3989020; Wed, 16 Jun 2021 08:44:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2627E3989020 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-1499] [Ada] Implementation of AI12-0152: legality rules for Raise_Expression X-Act-Checkin: gcc X-Git-Author: Ed Schonberg X-Git-Refname: refs/heads/master X-Git-Oldrev: c50041b99bc621cc1e2c7b7dbb67c0600926072e X-Git-Newrev: a2d2310d80ae992306f97764a850c56e70a1a8e3 Message-Id: <20210616084417.2627E3989020@sourceware.org> Date: Wed, 16 Jun 2021 08:44:17 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jun 2021 08:44:17 -0000 https://gcc.gnu.org/g:a2d2310d80ae992306f97764a850c56e70a1a8e3 commit r12-1499-ga2d2310d80ae992306f97764a850c56e70a1a8e3 Author: Ed Schonberg Date: Thu Feb 18 11:09:36 2021 -0500 [Ada] Implementation of AI12-0152: legality rules for Raise_Expression gcc/ada/ * sem_res.adb (Resolve_Raise_Expression): Apply Ada_2020 rules concerning the need for parentheses around Raise_Expressions in various contexts. Diff: --- gcc/ada/sem_res.adb | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index a57038528ad..e043085fbb9 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -10532,8 +10532,57 @@ package body Sem_Res is if Typ = Raise_Type then Error_Msg_N ("cannot find unique type for raise expression", N); Set_Etype (N, Any_Type); + else Set_Etype (N, Typ); + + -- Apply check for required parentheses in the enclosing + -- context of raise_expressions (RM 11.3 (2)), including default + -- expressions in contexts that can include aspect specifications, + -- and ancestor parts of extension aggregates. + + declare + Par : Node_Id := Parent (N); + Parentheses_Found : Boolean := Paren_Count (N) > 0; + + begin + while Present (Par) + and then Nkind (Par) in N_Has_Etype + loop + if Paren_Count (Par) > 0 then + Parentheses_Found := True; + end if; + + if Nkind (Par) = N_Extension_Aggregate + and then N = Ancestor_Part (Par) + then + exit; + end if; + + Par := Parent (Par); + end loop; + + if not Parentheses_Found + and then Comes_From_Source (Par) + and then + ((Nkind (Par) in N_Modular_Type_Definition + | N_Floating_Point_Definition + | N_Ordinary_Fixed_Point_Definition + | N_Decimal_Fixed_Point_Definition + | N_Extension_Aggregate + | N_Discriminant_Specification + | N_Parameter_Specification + | N_Formal_Object_Declaration) + + or else (Nkind (Par) = N_Object_Declaration + and then + Nkind (Parent (Par)) /= N_Extended_Return_Statement)) + then + Error_Msg_N + ("raise_expression must be parenthesized in this context", + N); + end if; + end; end if; end Resolve_Raise_Expression;