Given two interface types Ifc0 and Ifc1 where Ifc1 is a descendant of
Ifc0, the frontend reports a spurious error handling a call to a
Generic_Dispatching_Constructor instance that occurs as the operand of a
qualified expression initializing an allocator where Ifc1'Class is the
subtype_mark of the qualified expression and the designated type of the
type of the allocator is Ifc0'Class, as in the following example:
type Ref is access Ifc0'Class;
Ptr : Ref := new Ifc1'Class (<gdc call>);
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_ch6.adb (Make_Build_In_Place_Iface_Call_In_Allocator):
Build the internal anonymous access type using as a reference
the designated type imposed by the context (instead of using the
return type of the called function).
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
@@ -9709,7 +9709,8 @@ package body Exp_Ch6 is
-- declaration.
Anon_Type := Create_Itype (E_Anonymous_Access_Type, Function_Call);
- Set_Directly_Designated_Type (Anon_Type, Etype (BIP_Func_Call));
+ Set_Directly_Designated_Type (Anon_Type,
+ Designated_Type (Etype (Allocator)));
Set_Etype (Anon_Type, Anon_Type);
Build_Class_Wide_Master (Anon_Type);