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] |
When the type of an object is a CPP type and the object initialization requires calling its default C++ constructor, the Ada compiler did not generate the call to a C++ constructor which has all parameters with defaults (and hence it covers the default C++ constructor). The following test must now compile and execute well. // c_class.h class Tester { public: Tester(unsigned int a_num = 5, char* a_className = 0); virtual int dummy(); }; // c_class.cc #include "c_class.h" #include <iostream> Tester::Tester(unsigned int a_num, char* a_className) { std::cout << " ctor Tester called " << a_num << ":"; if (a_className == 0) { std::cout << "null"; } std::cout << std::endl; } int Tester::dummy() { } -- c_class_h.ads pragma Ada_2005; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; with Interfaces.C.Strings; package c_class_h is package Class_Tester is type Tester is tagged limited record null; end record; pragma Import (CPP, Tester); function New_Tester (a_num : unsigned := 5; a_className : Interfaces.C.Strings.chars_ptr := Interfaces.C.Strings.Null_Ptr) return Tester; pragma CPP_Constructor (New_Tester, "_ZN6TesterC1EjPc"); function dummy (this : access Tester) return int; pragma Import (CPP, dummy, "_ZN6Tester5dummyEv"); end; use Class_Tester; end c_class_h; -- main.adb with c_class_h; use c_class_h; procedure Main is use Class_Tester; Obj : Tester; -- Test pragma Unreferenced (Obj); begin null; end main; project Ada2Cppc is for Languages use ("Ada", "C++"); for Main use ("main.adb"); package Naming is for Implementation_Suffix ("C++") use ".cc"; end Naming; for Source_Dirs use ("."); for Object_Dir use "obj"; package Compiler is for Default_Switches ("ada") use ("-gnat05"); end Compiler; package Builder is for Default_Switches ("ada") use ("-g"); end Builder; package Ide is for Compiler_Command ("ada") use "gnatmake"; for Compiler_Command ("c") use "gcc"; end Ide; end Ada2Cppc; Command: mkdir obj gprclean -q -P ada2cppc.gpr gprbuild -q -P ada2cppc.gpr obj/main Output: ctor Tester called 5:null Tested on x86_64-pc-linux-gnu, committed on trunk 2012-10-02 Javier Miranda <miranda@adacore.com> * exp_disp.adb (Set_CPP_Constructors): Handle constructor with default parameters that covers the default constructor.
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] |