From patchwork Thu Sep 1 11:00:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 112869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6E4D8B6F80 for ; Thu, 1 Sep 2011 21:00:29 +1000 (EST) Received: (qmail 31046 invoked by alias); 1 Sep 2011 11:00:27 -0000 Received: (qmail 31032 invoked by uid 22791); 1 Sep 2011 11:00:26 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Sep 2011 11:00:13 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 600E92BB08D; Thu, 1 Sep 2011 07:00:12 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id v+3+C3sFJfLf; Thu, 1 Sep 2011 07:00:12 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 493812BAFD4; Thu, 1 Sep 2011 07:00:12 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 4512D3FEE8; Thu, 1 Sep 2011 07:00:12 -0400 (EDT) Date: Thu, 1 Sep 2011 07:00:12 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [Ada] Handle non-default C++ constructor call of non-tagged type Message-ID: <20110901110012.GA29349@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 * 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.