public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Gabriel Dos Reis <gdr@codesourcery.com>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org
Subject: Re: c++/4035: g++ actually copies a returned object when returning from a function/operator
Date: Thu, 16 Aug 2001 06:06:00 -0000	[thread overview]
Message-ID: <20010816130601.18604.qmail@sourceware.cygnus.com> (raw)

The following reply was made to PR c++/4035; it has been noted by GNATS.

From: Gabriel Dos Reis <gdr@codesourcery.com>
To: zach@cs.uni-bonn.de
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/4035: g++ actually copies a returned object when returning from a function/operator
Date: 16 Aug 2001 14:56:49 +0200

 zach@cs.uni-bonn.de writes:
 
 [...]
 
 | It seems to me that g++ actually copies a value when it sees a 'return X'
 | and when X is of class type.
 
 That is a conformant behaviour, assuming the return type has the same type.
 
 | If so, I think this is a major missing feature, if not really a big problem.
 | The standard does not require a copy.
 
 The standard explicitly says that that 
 	
 	return X;
 
 is semantically a copy-initialization :
 
 	ReturnType return_value = X;
 
 So, copying is a conformant behaviour.
 	
 | In fact, it explicitely allows to omit the copy completely -
 | see [class.tempoorary] and [class.copy, clause 15]:
 
 That permission isn't a requirement.  And in that respect g++ is
 violating no standard rule.
 
 And even if the actual copy is elided, the copy-contructor must be
 "callable". 
 
 [...]
 
 | In the example file I have attached, there is this piece of code:
 | 
 |     Dop DopTransform::operator * ( const Dop &dop ) const
 |     {
 |         Dop result;
 |         for ( int k = 0; k < NumOri; k ++ )
 |                 result[k] =   c[k][0] * dop[ Bb[k][0] ]
 |                             + c[k][1] * dop[ Bb[k][1] ]
 |                             + c[k][2] * dop[ Bb[k][2] ]
 |                             + o[k];
 |         return result;
 |     }
 | 
 | I get an error message saying
 | 
 | 	ColDopTree.cpp:226: no matching function for call to `col::Dop::Dop(col::Dop&)'
 | 	ColDopTree.h:74: candidates are: col::Dop::Dop(const col::Dop*)
 | 	ColDopTree.h:73:                 col::Dop::Dop(const osg::Pnt3f&)
 
 g++ is right.
 
 | (see the full output of g++ below).
 | 
 | This is because I have defined the copy constructor of class Dop 'explicit' like
 | this (of course):
 | 
 |     explicit Dop( const Dop &source );
 
 What usefulness is that?  Declaring a copy-constructor `explicit' is
 asking for trouble.
 
 | I should add, maybe, that my code compiles without any problems/warnings
 | on SGI (with SGI's C++ compiler) and under cygwin with Intel's compiler.
 
 That compiler is wrong then.
 
 Please remove the 'explicit' specifier from the copy-constructor
 declaration, it is not useful.
 
 -- Gaby


             reply	other threads:[~2001-08-16  6:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-16  6:06 Gabriel Dos Reis [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-08-17  9:36 gdr
2001-08-16  5:16 zach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010816130601.18604.qmail@sourceware.cygnus.com \
    --to=gdr@codesourcery.com \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).