diff mbox series

[Ada] Spurious error on parameterless acccess_to_subprogram

Message ID 20200710094420.GA35495@adacore.com
State New
Headers show
Series [Ada] Spurious error on parameterless acccess_to_subprogram | expand

Commit Message

Pierre-Marie de Rodat July 10, 2020, 9:44 a.m. UTC
Compiler rejects an indirect call through an Access_To_Subprogram
value that denotes a parameterless subprogram, when the corresponding
access type has a pre- or postcondition.

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

gcc/ada/

	* exp_ch3.adb (Build_Access_Subprogram_Wrapper_Body): Create a
	proper signature when the access type denotes a parameterless
	subprogram.
	* exp_ch6.adb (Expand_Call): Handle properly a  parameterless
	indirect call when the corresponding access type has contracts.
diff mbox series

Patch

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -547,10 +547,10 @@  package body Exp_Ch3 is
       Act := First (Parameter_Specifications (Spec_Node));
 
       while Present (Act) loop
+         exit when Act = Last (Parameter_Specifications (Spec_Node));
          Append_To (Actuals,
            Make_Identifier (Loc, Chars (Defining_Identifier (Act))));
          Next (Act);
-         exit when Act = Last (Parameter_Specifications (Spec_Node));
       end loop;
 
       Ptr :=


diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -2686,9 +2686,10 @@  package body Exp_Ch6 is
               Access_Subprogram_Wrapper (Etype (Name (N)));
             Ptr      : constant Node_Id   := Prefix (Name (N));
             Ptr_Type : constant Entity_Id := Etype (Ptr);
-            Parms    : constant List_Id   := Parameter_Associations (N);
             Typ      : constant Entity_Id := Etype (N);
+
             New_N    : Node_Id;
+            Parms    : List_Id   := Parameter_Associations (N);
             Ptr_Act  : Node_Id;
 
          begin
@@ -2711,6 +2712,12 @@  package body Exp_Ch6 is
                Ptr_Act := Ptr;
             end if;
 
+            --  Handle parameterless subprogram.
+
+            if No (Parms) then
+               Parms := New_List;
+            end if;
+
             Append
              (Make_Parameter_Association (Loc,
                 Selector_Name => Make_Identifier (Loc,