diff mbox series

[Ada] AI12-0095 Formal types and Constrained Partial Views

Message ID 20201022121212.GA4106@adacore.com
State New
Headers show
Series [Ada] AI12-0095 Formal types and Constrained Partial Views | expand

Commit Message

Pierre-Marie de Rodat Oct. 22, 2020, 12:12 p.m. UTC
AI12-0095 is a binding interpretation that revises the RM to have a
general rule about how generic formal discriminated types are considered
to have a constrained partial view within generic bodies, rather than
just have this rule appear in the sections of the RM on Access
attributes and type conversions, so that rule now also applies on the
rules for passing aliased parameters. GNAT was already implementing this
interpretation properly for parameters in generic bodies, but it was
noticed that a case involving Access in the spec of a generic unit was
not properly enforced in instantiations. If an Access attribute is
applied in a generic spec to a constrained aliased object of a formal
type with discriminants and in an instantiation the actual type has a
constrained partial view, then the Access attribute should be rejected
in the instantiation (assuming the access type in the generic has the
formal type as a designated subtype, with no constraint imposed). The
compiler was applying the function Has_Constrained_Partial_View to the
subtype that is created to rename the actual rather than to that
subtype's base type, so got a result of False rather than True. That
function is changed to apply Base_Type to its formal. Another fix is for
the case of a call with an aliased parameter of such a formal type that
occurs in a generic spec, which was incorrectly being flagged as
illegal, when it should be allowed in the generic spec and only rejected
in an instance (when the actual has a constrained partial view).

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

gcc/ada/

	* einfo.adb (Has_Constrained_Partial_View): Apply Base_Type to Id.
	* sem_res.adb (Resolve_Actuals.Check_Aliased_Parameter): Remove
	"not Is_Generic_Type" test and call
	Object_Type_Has_Constrained_Partial_View instead of
	Has_Constrained_Partial_View. Improve related error message to
	say "does not statically match" instead of just "does not
	match".
diff mbox series

Patch

diff --git a/gcc/ada/einfo.adb b/gcc/ada/einfo.adb
--- a/gcc/ada/einfo.adb
+++ b/gcc/ada/einfo.adb
@@ -1523,7 +1523,7 @@  package body Einfo is
    function Has_Constrained_Partial_View (Id : E) return B is
    begin
       pragma Assert (Is_Type (Id));
-      return Flag187 (Id);
+      return Flag187 (Base_Type (Id));
    end Has_Constrained_Partial_View;
 
    function Has_Controlled_Component (Id : E) return B is


diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -3479,13 +3479,13 @@  package body Sem_Res is
 
                elsif Has_Discriminants (F_Typ)
                  and then not Is_Constrained (F_Typ)
-                 and then not Has_Constrained_Partial_View (F_Typ)
-                 and then not Is_Generic_Type (F_Typ)
+                 and then not Object_Type_Has_Constrained_Partial_View
+                                (Typ => F_Typ, Scop => Current_Scope)
                then
                   null;
 
                else
-                  Error_Msg_NE ("untagged actual does not match "
+                  Error_Msg_NE ("untagged actual does not statically match "
                                 & "aliased formal&", A, F);
                end if;