From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31666 invoked by alias); 2 Jul 2005 18:21:21 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 31658 invoked by uid 22791); 2 Jul 2005 18:21:17 -0000 Received: from smtp18.wxs.nl (HELO smtp18.wxs.nl) (195.121.6.14) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Sat, 02 Jul 2005 18:21:17 +0000 Received: from brain.thuis (ip503d51d6.speed.planet.nl [80.61.81.214]) by smtp18.wxs.nl (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0IJ0002HJIZF86@smtp18.wxs.nl> for gcc-help@gcc.gnu.org; Sat, 02 Jul 2005 20:21:16 +0200 (CEST) Date: Sat, 02 Jul 2005 18:21:00 -0000 From: Jeroen Wijnhout Subject: copy ctor not called To: gcc-help@gcc.gnu.org Message-id: <200507022024.10598.Jeroen.Wijnhout@kdemail.net> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: inline User-Agent: KMail/1.8.50 X-SW-Source: 2005-07/txt/msg00015.txt.bz2 Hi, Consider a class with a copy constructor: class A { public: A(int i) : m_i(i) { cout << "A(int i)" << endl; } A(const A &a) { cout << "A(const A &a)" << endl; m_i = a.i(); } int i() { return m_i; } private: int m_i; }; now if I do something like: A a = 2; the output should be: A(int i) A(const A &a) the actual output is: A(int i) Now, I understand that gcc optimizes away the copy constructor and interprets the code as: A a(2); However, is there a way to force gcc to use the copy constructor? best, Jeroen P.S.: I'm not on the list. -- Kile -- KDE Integrated LaTeX Environment http://kile.sourceforge.net