diff mbox

[Ada] Expression functions and protected definitions

Message ID 20130129142715.GA10066@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Jan. 29, 2013, 2:27 p.m. UTC
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  <schonberg@adacore.com>

	* sem_ch6.adb (Analyze_Expression_Function): An expression
	function declaration is not a subprogram declaration, and thus
	cannot appear in a protected definition.
diff mbox

Patch

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);