diff mbox

[Ada] Spurious error on deferred constant in expression function

Message ID 20170425081240.GA36912@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 25, 2017, 8:12 a.m. UTC
This patch removes a spurious error on a deferred constant that appears
within an expression function, when the expression is being frozen by the
presence of its generated body. Such bodies are not a freeze point unless
they are completions.

The following must compile quietly:

---
package P is
   package S is
      type T is private;
      No_T : constant T;
      function Is_Null (A_T : T) return Boolean is (A_T = No_T);
   private
      type T is null record;
      No_T : constant T := (null record);
   end;
end P;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-04-25  Ed Schonberg  <schonberg@adacore.com>

	* freeze.adb (Check_Expression_Function): Do not check for the
	use of deferred constants if the freezing of the expression
	function is triggered by its generated body, rather than a
	premature use.
diff mbox

Patch

Index: freeze.adb
===================================================================
--- freeze.adb	(revision 247140)
+++ freeze.adb	(working copy)
@@ -1384,8 +1384,12 @@ 
    begin
       Decl := Original_Node (Unit_Declaration_Node (Nam));
 
+      --  The subprogram body created for the expression function is not
+      --  itself a freeze point.
+
       if Scope (Nam) = Current_Scope
         and then Nkind (Decl) = N_Expression_Function
+        and then Nkind (N) /= N_Subprogram_Body
       then
          Check_Deferred (Expression (Decl));
       end if;