From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31488 invoked by alias); 29 Sep 2005 11:53:06 -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 31468 invoked by uid 22791); 29 Sep 2005 11:53:02 -0000 Received: from qproxy.gmail.com (HELO qproxy.gmail.com) (72.14.204.203) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Thu, 29 Sep 2005 11:53:02 +0000 Received: by qproxy.gmail.com with SMTP id f9so28136qba for ; Thu, 29 Sep 2005 04:53:00 -0700 (PDT) Received: by 10.65.54.18 with SMTP id g18mr274326qbk; Thu, 29 Sep 2005 04:53:00 -0700 (PDT) Received: by 10.65.135.11 with HTTP; Thu, 29 Sep 2005 04:53:00 -0700 (PDT) Message-ID: Date: Thu, 29 Sep 2005 11:53:00 -0000 From: Dima Sorkin Reply-To: Dima Sorkin To: gcc-help@gcc.gnu.org Subject: temporary auto_ptr MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-SW-Source: 2005-09/txt/msg00209.txt.bz2 Hi. Some tricky question, just to understand how compiler thinks: See the example: //a.cpp -*-c++-*- ------------------------------------------------- #include using namespace std; class A{}; class B : public A {}; // This function does pass comilation auto_ptr f1(){ auto_ptr pB(new B); return auto_ptr(pB); } // This function doesn't pass compilation : why ? auto_ptr f2(){ auto_ptr pB(new B); return pB; } //----------------------------------------------------------------------= ----- Note: there exists template template auto_ptr::auto_ptr(auto_ptr &); non-explicit constructor Thank you. Dima. P.S. I tried to parse compiler's warnings and to understand what it does. gcc 4.0.1 just writes that conversion is ambiguous. gcc 3.3.4 : (as I understood) I don't undersand why in case of "f2" compiler tries to create a const temporary of auto_ptr as a part of cast process, for building a non-const temporary that "f2" returns (assuming there is no return-value optimizations in this stage). It can construct a non-const auto_ptr temporary that "f2" returns directly from auto_ptr instead.