From 73f05f9fe869c25fdcaf27f987016736322ca972 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Thu, 12 Nov 2015 11:09:59 +0000 Subject: [PATCH] exp_attr.adb (Compile_Stream_Body_In_Scope): When compiling a stream operation for an array type... 2015-11-12 Ed Schonberg * exp_attr.adb (Compile_Stream_Body_In_Scope): When compiling a stream operation for an array type, install the scope of the component type if it is private and not in scope, to prevent spurious errors if the full view of the component type has defaulted discriminants. From-SVN: r230234 --- gcc/ada/ChangeLog | 8 ++++++++ gcc/ada/exp_attr.adb | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index b8542eee6ab..9a799de64ec 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2015-11-12 Ed Schonberg + + * exp_attr.adb (Compile_Stream_Body_In_Scope): When compiling + a stream operation for an array type, install the scope of the + component type if it is private and not in scope, to prevent + spurious errors if the full view of the component type has + defaulted discriminants. + 2015-11-12 Eric Botcazou * sem_ch13.adb (Analyze_Attribute_Definition_Clause): For a diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index cb64c39230e..aaa3c728751 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -109,6 +109,16 @@ package body Exp_Attr is -- If we are within an instance body all visibility has been established -- already and there is no need to install the package. + -- This mechanism is now extended to the component types of the array type, + -- when the component type is not in scope and is private, to handle + -- properly the case when the full view has defaulted discriminants. + + -- This special processing is ultimately caused by the fact that the + -- compiler lacks a well-defined phase when full views are visible + -- everywhere. Having such a separate pass would remove much of the + -- special-case code that shuffles partial and full views in the middle + -- of semantic analysis and expansion. + procedure Expand_Access_To_Protected_Op (N : Node_Id; Pref : Node_Id; @@ -624,24 +634,43 @@ package body Exp_Attr is Arr : Entity_Id; Check : Boolean) is - Installed : Boolean := False; - Scop : constant Entity_Id := Scope (Arr); + C_Type : constant Entity_Id := Base_Type (Component_Type (Arr)); Curr : constant Entity_Id := Current_Scope; + Install : Boolean := False; + Scop : Entity_Id := Scope (Arr); + begin if Is_Hidden (Arr) and then not In_Open_Scopes (Scop) and then Ekind (Scop) = E_Package + then + Install := True; + else + + -- The component type may be private, in which case we install + -- its full view to compile the subprogram. - -- If we are within an instance body, then all visibility has been - -- established already and there is no need to install the package. + Scop := Scope (C_Type); + if Is_Private_Type (C_Type) + and then Present (Full_View (C_Type)) + and then not In_Open_Scopes (Scop) + and then Ekind (Scop) = E_Package + then + Install := True; + end if; + end if; + + -- If we are within an instance body, then all visibility has been + -- established already and there is no need to install the package. + + if Install and then not In_Instance_Body then Push_Scope (Scop); Install_Visible_Declarations (Scop); Install_Private_Declarations (Scop); - Installed := True; -- The entities in the package are now visible, but the generated -- stream entity must appear in the current scope (usually an @@ -649,6 +678,8 @@ package body Exp_Attr is -- scopes. Push_Scope (Curr); + else + Install := False; end if; if Check then @@ -657,7 +688,7 @@ package body Exp_Attr is Insert_Action (N, Decl, Suppress => All_Checks); end if; - if Installed then + if Install then -- Remove extra copy of current scope, and package itself -- 2.30.2