diff options
author | Ed Schonberg <schonberg@adacore.com> | 2018-08-21 14:47:32 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-08-21 14:47:32 +0000 |
commit | 41306c0a89a539c97e8eee0867816ea3ae5ab5b7 (patch) | |
tree | 349efba350e47ed7e58a62f6175bfb4c3a63ae94 | |
parent | 298e0c6bf77b2e218bd5f8a386ecfdd4e7c9ab52 (diff) | |
download | gcc-41306c0a89a539c97e8eee0867816ea3ae5ab5b7.zip gcc-41306c0a89a539c97e8eee0867816ea3ae5ab5b7.tar.gz gcc-41306c0a89a539c97e8eee0867816ea3ae5ab5b7.tar.bz2 |
[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.
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.
From-SVN: r263726
-rw-r--r-- | gcc/ada/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/ada/sem_res.adb | 13 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/access5.adb | 5 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/access5.ads | 10 |
5 files changed, 38 insertions, 1 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 0c558c0..5ac1463 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2018-08-21 Ed Schonberg <schonberg@adacore.com> + + * 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. + 2018-08-21 Yannick Moy <moy@adacore.com> * doc/gnat_ugn/building_executable_programs_with_gnat.rst: diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 13612aa..5a1a9f7 100644 --- a/gcc/ada/sem_res.adb +++ b/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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e0dfb3d..eccca9b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-08-21 Ed Schonberg <schonberg@adacore.com> + + * gnat.dg/access5.adb, gnat.dg/access5.ads: New testcase. + 2018-08-21 Eric Botcazou <ebotcazou@adacore.com> * gnat.dg/rep_clause7.adb: New testcase. diff --git a/gcc/testsuite/gnat.dg/access5.adb b/gcc/testsuite/gnat.dg/access5.adb new file mode 100644 index 0000000..1369ea0 --- /dev/null +++ b/gcc/testsuite/gnat.dg/access5.adb @@ -0,0 +1,5 @@ +-- { dg-do compile } + +package body Access5 is + procedure Dummy is null; +end; diff --git a/gcc/testsuite/gnat.dg/access5.ads b/gcc/testsuite/gnat.dg/access5.ads new file mode 100644 index 0000000..81ab3b3 --- /dev/null +++ b/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; |