From patchwork Tue Jan 29 14:27:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Expression functions and protected definitions Date: Tue, 29 Jan 2013 04:27:15 -0000 From: Arnaud Charlet X-Patchwork-Id: 216552 Message-Id: <20130129142715.GA10066@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg An expression_function_declaration is a different syntactic category from a subprogram_declaration. As a consequence, an expression function cannot appear in a protected definition, i.e. cannot declare a protected operation. Compiling essai.adb must yield: essai.adb:4:07: an expression function is not a legal protected operation essai.adb:7:07: an expression function is not a legal protected operation --- pragma Ada_2012; procedure Essai is protected P1 is function F1 return Integer is (1); function F2 return Integer; -- ERROR private function F3 return Boolean is (False); -- ERROR end P1; protected body P1 is function F2 return Integer is (1); -- OK end P1; begin null; end Essai; Tested on x86_64-pc-linux-gnu, committed on trunk 2013-01-29 Ed Schonberg * sem_ch6.adb (Analyze_Expression_Function): An expression function declaration is not a subprogram declaration, and thus cannot appear in a protected definition. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 195540) +++ sem_ch6.adb (working copy) @@ -408,6 +408,15 @@ -- that the expression can be inlined whenever possible. else + -- An expression function that is not a completion is not a + -- subprogram declaration, and thus cannot appear in a protected + -- definition. + + if Nkind (Parent (N)) = N_Protected_Definition then + Error_Msg_N + ("an expression function is not a legal protected operation", N); + end if; + New_Decl := Make_Subprogram_Declaration (Loc, Specification => Spec);