From: Arnaud Charlet Date: Mon, 22 Jun 2009 13:15:08 +0000 (+0200) Subject: [multiple changes] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6823270cb98959be5157725c7e0efd87c0b61e23;p=gcc.git [multiple changes] 2009-06-22 Javier Miranda * sem_ch3.adb (Analyze_Object_Declaration, Freeze_Entity): Move to the freezing point the check on the use of abstract types in object declarations. Done to allow the declaration of C++ imported variables or constants whose type corresponds with an imported C++ classes for which the constructor is not imported. 2009-06-22 Thomas Quinot * sem_ch6.adb: Minor reformatting 2009-06-22 Ed Schonberg * exp_ch3.adb (Build_Initialization_Call): If a discriminated record component is constrained with an expression rather than with a discriminant of the enclosing type, use that expression when building the call to default-initialize the component, when the call is part of an aggregate with box initialization. From-SVN: r148793 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 343de41a157..3fd0df33912 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,23 @@ +2009-06-22 Javier Miranda + + * sem_ch3.adb (Analyze_Object_Declaration, Freeze_Entity): Move to the + freezing point the check on the use of abstract types in object + declarations. Done to allow the declaration of C++ imported variables + or constants whose type corresponds with an imported C++ classes for + which the constructor is not imported. + +2009-06-22 Thomas Quinot + + * sem_ch6.adb: Minor reformatting + +2009-06-22 Ed Schonberg + + * exp_ch3.adb (Build_Initialization_Call): If a discriminated record + component is constrained with an expression rather than with a + discriminant of the enclosing type, use that expression when building + the call to default-initialize the component, when the call is part of + an aggregate with box initialization. + 2009-06-22 Ed Schonberg * sem_ch6.adb (Check_Overriding_Indicator): Clean up code, make warning diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb index 3b2cc64a0bd..219175b5a14 100644 --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -1565,14 +1565,17 @@ package body Exp_Ch3 is end if; -- Ada 2005 (AI-287): In case of default initialized components, - -- we need to generate the corresponding selected component node - -- to access the discriminant value. In other cases this is not - -- required because we are inside the init proc and we use the - -- corresponding formal. + -- if the component is constrained with a discriminant of the + -- enclosing type, we need to generate the corresponding selected + -- component node to access the discriminant value. In other cases + -- this is not required, either because we are inside the init + -- proc and we use the corresponding formal, or else because the + -- component is constrained by an expression. if With_Default_Init and then Nkind (Id_Ref) = N_Selected_Component and then Nkind (Arg) = N_Identifier + and then Ekind (Entity (Arg)) = E_Discriminant then Append_To (Args, Make_Selected_Component (Loc, diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index e68086cdc98..5a7d0ef47de 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -2670,6 +2670,28 @@ package body Freeze is if Nkind (Declaration_Node (E)) = N_Object_Declaration then + -- Abstract type allowed only for C++ imported variables or + -- constants. + + -- Note: we inhibit this check for objects that do not come + -- from source because there is at least one case (the + -- expansion of x'class'input where x is abstract) where we + -- legitimately generate an abstract object. + + if Is_Abstract_Type (Etype (E)) + and then Comes_From_Source (Parent (E)) + and then not (Is_Imported (E) + and then Is_CPP_Class (Etype (E))) + then + Error_Msg_N ("type of object cannot be abstract", + Object_Definition (Parent (E))); + + if Is_CPP_Class (Etype (E)) then + Error_Msg_NE ("\} may need a cpp_constructor", + Object_Definition (Parent (E)), Etype (E)); + end if; + end if; + -- For object created by object declaration, perform required -- categorization (preelaborate and pure) checks. Defer these -- checks to freeze time since pragma Import inhibits default diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 3e334686b73..47616825e35 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -2657,24 +2657,9 @@ package body Sem_Ch3 is end if; end if; - -- Abstract type is never permitted for a variable or constant. - -- Note: we inhibit this check for objects that do not come from - -- source because there is at least one case (the expansion of - -- x'class'input where x is abstract) where we legitimately - -- generate an abstract object. - - if Is_Abstract_Type (T) and then Comes_From_Source (N) then - Error_Msg_N ("type of object cannot be abstract", - Object_Definition (N)); - - if Is_CPP_Class (T) then - Error_Msg_NE ("\} may need a cpp_constructor", - Object_Definition (N), T); - end if; - -- Case of unconstrained type - elsif Is_Indefinite_Subtype (T) then + if Is_Indefinite_Subtype (T) then -- Nothing to do in deferred constant case diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index 1b4abcb6e6f..bb0da6d7538 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -4376,7 +4376,7 @@ package body Sem_Ch6 is -- The overriding operation is type conformant with the overridden one, -- but the names of the formals are not required to match. If the names - -- appear permuted in the overriding operation this is a possible + -- appear permuted in the overriding operation, this is a possible -- source of confusion that is worth diagnosing. Controlling formals -- often carry names that reflect the type, and it is not worthwhile -- requiring that their names match. @@ -4394,9 +4394,13 @@ package body Sem_Ch6 is -- If the overriding operation is a synchronized operation, skip -- the first parameter of the overridden operation, which is - -- implicit in the new one. + -- implicit in the new one. If the operation is declared in the + -- body it is not primitive and all formals must match. - if Is_Concurrent_Type (Scope (Subp)) then + if Is_Concurrent_Type (Scope (Subp)) + and then Is_Tagged_Type (Scope (Subp)) + and then not Has_Completion (Scope (Subp)) + then Form2 := Next_Formal (Form2); end if;