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] |
Tested on i686-linux, committed on trunk This patch improves the management of class-wide types visible through limited-with clauses. The following program now compiles without errors. -- package pkg1 is type I1 is interface; type I2 is interface; type T is new I1 and I2 with null record; end; -- package pkg1.impl is end; -- limited with Pkg1; package Pkg2 is function Test (Obj : pkg1.T'Class) return access pkg1.I2'Class; end; -- with Pkg1; package body Pkg2 is function Test (Obj : Pkg1.T'Class) return access pkg1.I2'Class is begin return null; end; end; -- Command: gcc -c pkg2.adb In Ada2005 anonymous access types with compatible designated types can be compared for equality, The operator is defined in standard and immediately visible, unless a proper user-defined operator exists. Cases of ambiguity are resolved later. gnat.dg/anon2.adb must compile quietly. Rule 3.10.1 (8 1/2) of Ada 2005 allows a tagged incomplete view of a type to be used as the subtype of a parameter in a formal part of a subprogram declaration. The formal part can be processed by Gigi before the full view is encountered. Therefore Is_By_Reference_Type must return true for the tagged incomplete view, as it does for any tagged types, in order for Gigi to correctly translate the subprogram declaration. gnat.dg/ref_type.adb must compile silently. Also, the equality function declared on universal access types applies as well to access to subprogram types, to enforce the legality rule of 4.5.2(9.2).. The code had omitted to include access to subprograms, when finding a common type to which to convert operands of some binary operator. gnat.dg/equal_access.adb must compile quietly. If the first formal of a primitive operation is an access parameter, the prefix in a call is allowed to be an object of the designated type, and an implicit 'Access is created for the first actual. However this is not legal if the object is not aliased. This patch simply improves on the error message generated for this case. Compilation of cl.adb in Ada 2005 mode must procedure the following. -- cl.adb:12:05: object in prefixed call to "CW_Proc" must be aliased (RM-2005 4.3.1 (13)) cl.adb:13:05: object in prefixed call to "Prim_Proc" must be aliased (RM-2005 4.3.1 (13)) -- package pref is type Base is tagged null record; procedure CW_Proc (Obj : access Base'Class); procedure Prim_Proc (Obj : access Base); end pref; -- with Pref; use Pref; procedure Cl is A : access Base := new Base; A_O : Base := A.all; -- BC_A : access Base'Class := new Base; BC_O : Base'Class :=BC_A.all; -- begin BC_A.CW_Proc; BC_O.CW_Proc; -- error : not Aliased. A_O.Prim_Proc; -- error : not Aliased. A.Prim_Proc; end Cl; Finally, prefixed notation combined with implicit dereference and implicit 'access can lead to ambiguous calls between primitive operations that do not hide each other. Compilation of Client below must produce the following output: -- client.adb:12:09: ambiguous call to "CW_Proc" client.adb:12:09: possible interpretation at prefix.ads:6 client.adb:12:09: possible interpretation (with implicit dereference) at prefix.ads:5 client.adb:13:09: ambiguous call to "CW_Proc" client.adb:13:09: possible interpretation (with implicit Access) at prefix.ads:6 client.adb:13:09: possible interpretation at prefix.ads:5 client.adb:14:08: ambiguous call to "Prim_Proc" client.adb:14:08: possible interpretation at prefix.ads:7 client.adb:14:08: possible interpretation (with implicit Access) at prefix.ads:8 client.adb:15:06: ambiguous call to "Prim_Proc" client.adb:15:06: possible interpretation (with implicit dereference) at prefix.ads:7 client.adb:15:06: possible interpretation at prefix.ads:8 -- package Prefix is type Base is tagged null record; -- procedure CW_Proc (Obj : Base'Class); procedure CW_Proc (Obj : access Base'Class); procedure Prim_Proc (Obj : Base); procedure Prim_Proc (Obj : access Base); end Prefix; -- with Prefix; use Prefix; procedure Client is A : access Base := new Base; A_O : aliased Base := A.all; -- BC_A : access Base'Class := new Base; BC_O : aliased Base'Class :=BC_A.all; -- begin -- if A_O'access= null then raise program_error; end if; BC_A.CW_Proc; BC_O.CW_Proc; A_O.Prim_Proc; A.Prim_Proc; end Client; 2007-06-06 Javier Miranda <miranda@adacore.com> Ed Schonberg <schonberg@adacore.com> Robert Dewar <dewar@adacore.com> Eric Botcazou <ebotcazou@adacore.com> Arnaud Charlet <charlet@adacore.com> * einfo.ads, einfo.adb (Available_View): New synthesized attribute applicable to types that have the With_Type flag set. Returns the non-limited view of the type, if available, otherwise the type itself. For class-wide types, there is no direct link in the tree, so we have to retrieve the class-wide type of the non-limited view of the Etype. New attributes Static_Initialization and Static_Elaboration_Desired. Remove the pragma Thread_Body, and the associated flag Is_Thread_Body in entities, and all related code. (Suppress_Value_Tracking_On_Call): New flag E_Exception has Esize and Alignment fields (Universal_Aliasing): New function. (Set_Universal_Aliasing): New procedure. (Write_Entity_Flags): Deal with Universal_Aliasing flag. (Check_Nested_Access): New procedure. (Has_Up_Level_Access, Set_Has_Up_Level_Access): New procedures. (Find_Direct_Name, Note_Possible_Modification): Use Check_Nested_Access. (Related_Interface): New attribute. Present in dispatch table pointer components of records. Set to point to the entity of the corresponding interface type. (Is_By_Reference_Type): Recurse on the full view of an incomplete type. (Original_Access_Type): Remove, not needed. (Root_Type): Handle properly subtypes of class-wide-types. Update comments. * sem_ch4.adb (Analyze_Explicit_Dereference): Add support for class-wide types visible through limited-with clauses. (Try_Primitive_Operation): When examining all primitive operations of a tagged type, do not consider subprograms labeled as hidden unless they belong to a private generic type with a tagged parent. (Try_Object_Operation): Extensive rewriting, to handle properly various overloading cases, when several ancestors may have class-wide operations that are possible candidates, and when the overloaded functions return array types and have defaulted parameters so that the call may be interpreted as an indexing. (Analyze_Allocator): Remove Mark_Allocator and its invocation. (Process_Function_Call): use Next, rather than Next_Actual, to analyze successive actuals before analyzing the call itself. (Try_Primitive_Operation): A primitive operation is compatible with the prefix if the prefix has a synchronized type and the type of the formal is its corresponding record, as can be the case when the primitive operation is declared outside of the body of the type. (Traverse_Homonyms): New subprocedure of Try_Class_Wide_Operation, to perform homonym traversal, looking for class-wide operation matches (formerly done in statements of Try_Class_Wide_Operation). Matches on access parameters are now restricted to anonymous access types. (Mark_Allocator): An allocator with a discriminant association parent is a coextension. (Try_One_Prefix_Interpretation): If the type of the object is incomplete, as can be happen when it is a limited view obtained through a limited_with_clause, the selected component is not part of a prefixed call. (Complete_Object_Operation): Diagnose properly an object that is not aliased when the corresponding controlling formal is an access parameter. (Try_Primitive_Operation, Try_Class_Wide_Operation): Diagnose properly ambiguous calls in prefixed notation, where two primitives differ only in that the controlling argument of one is an access parameter. * sem_ch6.adb (Has_Single_Return): Add guard in code that determines whether a function that returns an unconstrained type can be inlined. (Process_Formals): Diagnose properly the illegal use of an incomplete type in the profile of an access_to_subprogram declaration. (Check_Synchronized_Overriding): Nothing check for concurrent types, the operations are attached to the corresponding record. (Analyze_Subprogram_Specification): Add variables Formal and Formal_Typ. When processing a primitive of a concurrent type which implements an interface change the type of all controlling formals to that of the corresponding record type. (Check_Synchronized_Overriding): Relax the conditional logic when trying to determine the tagged type to which a primitive belongs. (Check_Conventions): Capture condition to ignore a primitive operation (which is shared between the loop in Check_Conventions and the one in Check_Convention) in a new local function Skip_Check. (Check_Convention): Rename Prim_Op to Second_Prim_Op to avoid possible confusion with Check_Conventions' own Prim_Op local variable. (Create_Extra_Formals): Test for a tagged result type rather than a controlling result when determining whether to add a BIP_Alloc_Form formal and a BIP_Final_List formal to the function. (Check_Conformance); For parameters that are anonymous access types, subtype conformance requires that the not null and the constant indicators must match (Check_Synchronized_Overriding): New parameter Formal_Typ. Add machinery to retrieve the appropriate type when processing a concurrent type declared within a generic. Minor comment reformatting. Change invocation of Overrides_Synchronized_Primitive to Find_Overridden_Synchronized_Pri- mitive. (Analyze_Subprogram_Body): If the return type of a function is an anonymous access to the limited view of a class-wide type, and the non-limited view of the type is available, update the type of the function so that code can be generated. (Process_Formals): In case of access-subtype itype whose designated type is also an itype (situation that happens now with access to subprograms) we mark the access-type itype with the Has_Delayed_Freeze attribute to avoid backend problems. (Check_Return_Subtype_Indication): Replace R_Type with R_Stm_Type in init of R_Stm_Type_Is_Anon_Access. Also check that base types of the anonymous types' designated types are same before testing Subtypes_Statically_Match. (Create_Extra_Formals): Test for a named access parameter that is a controlling formal as an additional condition for adding an accessibility level formal. This can occur in the subp type created for dispatching calls in Expand_Dispatching_Call, and allows calling Create_Extra_Formals from that procedure rather than special-casing the extra formals there. (Create_Extra_Formals): Add BIP_Alloc_Form and BIP_Final_List formals when the function has a controlling result. (Check_Returns): Add much more knowledge of the optimization of local raise statements to gotos, to retain proper warnings in this case. (Check_Statement_Sequence): Ignore N_Push_xxx_Label and N_Pop_xxx_Label nodes when looking for last statement. * sem_type.ads, sem_type.adb (Specific_Type): Add support for class-wide types visible through limited with clauses. (Add_One_Interp): If the operands are anonymous access types, the predefined operator on universal_access is immediately visibles (Find_Unique_Type): Handle anonymous access to subprogram types just as other anonymous access types. (Disambiguate): Take into account CIL convention. (Interface_Present_In_Ancestor): Add support for class-wide interfaces.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |