This is the mail archive of the 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]

[Ada] Non-default C++ constructors and allocators

This patch adds the missing support for calling non-default C++
constructors in the qualified expression used to initialize an
allocated object. The following test now compiles and executes
without errors.

//root.h -----------------------------------------------
class Root {
  int  o_value;
  virtual void prim();
  Root();      // Default constructor

//root.cpp ---------------------------------------------
#include "root.h"
void Root::prim() {

Root::Root() {
  o_value = 998;

-- -----------------------------------
package Pkg_CPP_Class is
   type Root is tagged limited record
      O_Value : Integer;
   end record;
   pragma Import (CPP, Root);

   procedure Prim (Obj : Root);
   pragma Import (CPP, Prim);

   function Constructor return Root'Class;
   pragma Cpp_Constructor (Constructor, "_ZN4RootC1Ev");
end Pkg_CPP_Class;

-- do_test.adb -----------------------------------------
with Pkg_CPP_Class; use Pkg_CPP_Class;
procedure Do_Test is
   Ptr : access Root := new Root;
   if Ptr.o_value /= 998 then
      raise Program_Error;
   end if;

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

2009-06-25  Javier Miranda  <>

	* sem_res.adb (Resolve_Allocator): Skip test requiring exact match of
	types on qualified expression in calls to imported C++ constructors.

	* exp_ch4.adb (Expand_Allocator_Expression): Add missing support for
	imported C++ constructors.

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]