public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "robert dot schweikert at abaqus dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/14823] the copy constructor is called unnecessarily/incorrectly when passing an arg by reference to the base class
Date: Mon, 05 Apr 2004 13:17:00 -0000	[thread overview]
Message-ID: <20040405131729.4587.qmail@sources.redhat.com> (raw)
In-Reply-To: <20040402143013.14823.robert.schweikert@abaqus.com>


------- Additional Comments From robert dot schweikert at abaqus dot com  2004-04-05 13:17 -------
Subject: Re:  the copy constructor is called
	unnecessarily/incorrectly when passing an arg by reference to the base class

On Sat, 2004-04-03 at 12:07, giovannibajo at libero dot it wrote:
> ------- Additional Comments From giovannibajo at libero dot it  2004-04-03 17:07 -------
> (In reply to comment #6)
> 
> > The text can be found in the first sub bullet of bullet 5 in section
> > 8.5.3 and IMHO this is the case that applies here as the rvalue of
> > omu_VarrayPtr() can be converted to an lvalue 
> 
> Where exactly does the standard speak of a rvalue-to-lvalue conversion? 

That would be on page 147 in the [dcl.init.ref] section (8.5.3) bullet
5.

> There 
> is a lvalue-to-rvalue conversion which happens when lvalues appear in contexts 
> in which rvalues are expected (see [basic.lval]/7, and [conv.lval]), but not 
> the other way round. 

Well it reads

"
- has a class type (i.e. T2 is a class type) and can be implicitly
converted to an lvalue ....
"

So T2 in this case would be the rvalue and the reference would be bound
to the result of the conversion (lvalue).

At the end of the page one can find the following note:

"
[Note the usual lvalue-to-rvalue (4.1), array-to-pointer (4.2), and
function-to-pointer (4.3) standard conversions are not needed, and
therefore are suppressed, when such direct bindings to lvalues are
done.]
"

> 
> If any rvalue could be converted to a lvalue and vice versa, why would we have 
> a difference in the first place?
> 
> The expression omu_VarrayPtr() is an rvalue, period ([basic.lval]/6).

No argument there.

>  Your 
> first sub-bullet cannot be applied;

Correct I am not saying it should.

>  you have to look into the rvalue case, 
> which is covered by bullet 2, sub-bullet 1 (as referenced in the bugs.html 
> page). 
> 
> Now, this must be the 5th time I answer this. What on earth do we have to do 
> more than adding a FAQ, as we already did?

Well, I am not sure about that. I know repetitive questions can be
frustrating.

Lets consider the following simple example:

template <class T>
class AT
{
public:
    AT();
    virtual T& getType();
    virtual ~AT();
private:
    AT(const AT<T>&); // private copy ctor
};


class A
{
public:
    A();
    virtual ~A();
private:
    A(const A&);  // private copy ctor
};

typedef AT<A> ATuse;

class foo
{
    public:
      foo(const ATuse&, const ATuse&);
};

class bar : public foo
{
    public:
       bar(const ATuse&);
};

bar::bar(const ATuse& ola) : foo(ola, ATuse())
{
}


ATuse() in the initialization of the foo base class in the bar ctor is
an rvalue and the foo ctor expects a const ref as the second argument.
Both copy constructors (template, and the type used for the template)
are private, yet the code compiles just fine. The schematics are the
same as in the test case (i file attached to the bug report), yet this
simple example compiles just fine. This indicates to me that the
compiler is getting confused by something and that the direct binding as
described in bullet 5 sub bullet 2 in section 8.5.3 actually works.

I have not thought about how to track down the point where the compiler
is getting confused.

Thanks,
Robert



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14823


  parent reply	other threads:[~2004-04-05 13:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-02 14:30 [Bug c++/14823] New: " robert dot schweikert at abaqus dot com
2004-04-02 14:31 ` [Bug c++/14823] " robert dot schweikert at abaqus dot com
2004-04-02 14:47 ` pinskia at gcc dot gnu dot org
2004-04-02 15:18 ` robert dot schweikert at abaqus dot com
2004-04-02 17:41 ` bangerth at dealii dot org
2004-04-02 18:01 ` pinskia at gcc dot gnu dot org
2004-04-02 18:22 ` robert dot schweikert at abaqus dot com
2004-04-03 17:08 ` giovannibajo at libero dot it
2004-04-05 13:17 ` robert dot schweikert at abaqus dot com [this message]
2004-04-05 13:20 ` robert dot schweikert at abaqus dot com
2004-04-05 13:45 ` robert dot schweikert at abaqus dot com
2004-04-05 13:50 ` giovannibajo at libero dot it
2004-04-07 13:57 ` robert dot schweikert at abaqus dot com
2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
2004-08-27  8:51 ` pinskia at gcc dot gnu dot org

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=20040405131729.4587.qmail@sources.redhat.com \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).