This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Spurious ambiguity error on call returning an access type


If F is a function with a single defaulted parameter that returns an
access_to_array type, then F (I) may designate either the return type or
an indexing of the result of the call, after implicit dereferencing.  If
the component type C of the array type AR is accces AR this is ambiguous
in a context whose expected type is C. If F is parameterless the call is
not ambiguous.

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

2018-08-21  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_res.adb (Resolve_Call): Resolve correctly a parameterless
	call that returns an access type whose designated type is the
	component type of an array, when the function has no defaulted
	parameters.

gcc/testsuite/

	* gnat.dg/access5.adb, gnat.dg/access5.ads: New testcase.
--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -6128,7 +6128,18 @@ package body Sem_Res is
             Ret_Type   : constant Entity_Id := Etype (Nam);
 
          begin
-            if Is_Access_Type (Ret_Type)
+            --  If this is a parameterless call there is no ambiguity
+            --  and the call has the type of the function.
+
+            if No (First_Actual (N)) then
+               Set_Etype (N, Etype (Nam));
+               if Present (First_Formal (Nam)) then
+                  Resolve_Actuals (N, Nam);
+               end if;
+               Build_Call_Marker (N);
+
+            elsif Is_Access_Type (Ret_Type)
+
               and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
             then
                Error_Msg_N

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/access5.adb
@@ -0,0 +1,5 @@
+--  { dg-do compile }
+
+package body Access5 is
+  procedure Dummy is null;
+end;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/access5.ads
@@ -0,0 +1,10 @@
+package Access5 is
+  type Vec;
+  type Ptr is access all Vec;
+  type Vec is array (1..3) of Ptr;
+  function F return Ptr;
+  pragma Import (Ada, F);
+  Tail : Vec := (F, F, F);
+
+  procedure Dummy;
+end;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]