This patch enables the frontend support for calling C++ constructors
of non-tagged types. This is required since the equivalent Ada type
of a C++ class that has no virtual methods is a non-tagged limited
record type. After this patch the following test executes well.
class demo
{
int value;
public:
demo (int init_value);
void display (void);
};
#include "stdio.h"
#include "demo_class.h"
demo::demo (int init_value)
{
this->value = init_value;
}
void demo::display ()
{
printf ("value %d\n", value);
}
with Demo_Class_H;
procedure Call_Cpp is
Obj2 : aliased Demo_Class_H.Class_Demo.demo :=
Demo_Class_H.Class_Demo.New_Demo (42);
begin
Demo_Class_H.Class_Demo.Display (Obj2'Access);
end Call_Cpp;
Command:
g++ -c -fdump-ada-spec -C demo_class.h
gnatchop -w -gnat05 all.ada
gprbuild -q demo.gpr
./call_cpp
Output:
value 42
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-09-01 Javier Miranda <[email protected]>
* exp_ch3.adb (Expand_N_Object_Declaration): Handle non-default
constructor calls associated with non-tagged record types.
Index: exp_ch3.adb
===================================================================
--- exp_ch3.adb (revision 178381)
+++ exp_ch3.adb (working copy)
@@ -5129,9 +5129,13 @@
Loc))));
end;
- elsif Is_Tagged_Type (Typ)
- and then Is_CPP_Constructor_Call (Expr)
- then
+ -- Handle C++ constructor calls. Note that we do not check that
+ -- Typ is a tagged type since the equivalent Ada type of a C++
+ -- class that has no virtual methods is a non-tagged limited
+ -- record type.
+
+ elsif Is_CPP_Constructor_Call (Expr) then
+
-- The call to the initialization procedure does NOT freeze the
-- object being initialized.