exp_aggr.adb (Build_Record_Aggr_Code): Add implicit call to the C++ constructor in...
authorJavier Miranda <miranda@adacore.com>
Wed, 6 May 2009 08:28:40 +0000 (08:28 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Wed, 6 May 2009 08:28:40 +0000 (10:28 +0200)
2009-05-06  Javier Miranda  <miranda@adacore.com>

* exp_aggr.adb (Build_Record_Aggr_Code): Add implicit call to the C++
constructor in case of aggregates whose type is a CPP_Class type.

From-SVN: r147151

gcc/ada/ChangeLog
gcc/ada/exp_aggr.adb

index f5da41edb9bd3229468d0649b153c03701533afb..4d7bb5659114496d98d5dde84c46f55374d56786 100644 (file)
@@ -1,3 +1,8 @@
+2009-05-06  Javier Miranda  <miranda@adacore.com>
+
+       * exp_aggr.adb (Build_Record_Aggr_Code): Add implicit call to the C++
+       constructor in case of aggregates whose type is a CPP_Class type.
+
 2009-05-06  Robert Dewar  <dewar@adacore.com>
 
        * sem_ch13.adb: Minor comment additions
index 516905f88732298ce52945b946493da9791e48be..6645bea388d92b949f1fb50c180a4955970d919a 100644 (file)
@@ -2765,6 +2765,18 @@ package body Exp_Aggr is
          end if;
       end if;
 
+      --  For CPP types we generate an implicit call to the C++ default
+      --  constructor to ensure the proper initialization of the _Tag
+      --  component.
+
+      if Is_CPP_Class (Typ) then
+         pragma Assert (Present (Base_Init_Proc (Typ)));
+         Append_List_To (L,
+           Build_Initialization_Call (Loc,
+             Id_Ref => Lhs,
+             Typ    => Typ));
+      end if;
+
       --  Generate the assignments, component by component
 
       --    tmp.comp1 := Expr1_From_Aggr;
@@ -3129,6 +3141,13 @@ package body Exp_Aggr is
       if Ancestor_Is_Expression then
          null;
 
+      --  For CPP types we generated a call to the C++ default constructor
+      --  before the components have been initialized to ensure the proper
+      --  initialization of the _Tag component (see above).
+
+      elsif Is_CPP_Class (Typ) then
+         null;
+
       elsif Is_Tagged_Type (Typ) and then VM_Target = No_VM then
          Instr :=
            Make_OK_Assignment_Statement (Loc,