public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb@sourceware.org
Subject: Re: PR symtab/14441 - rvalue references
Date: Mon, 29 Oct 2012 23:40:00 -0000	[thread overview]
Message-ID: <CAH6eHdTrG8JuAxvWDXn_R+C18fZzkPetMoEY211i0318BTSMTA@mail.gmail.com> (raw)
In-Reply-To: <87txtdz76a.fsf@fleche.redhat.com>

On 29 October 2012 14:25, Tom Tromey wrote:
> Jonathan> Before I continue altering every function that checks TYPE_CODE_REF,
> Jonathan> is my approach the right one?  Is adding TYPE_CODE_RVAL_REF and
> Jonathan> touching dozens of functions the best approach, or should I go back to
> Jonathan> my first attempt and just fix the few places that need to handle
> Jonathan> lvalue and rvalue references differently?
>
> I would accept either one.  Abstractly, I suppose a new type code would
> be more in keeping with the current design.  But I think the other
> choice would be ok, too, if it is a reasonably accurate model of C++.  I
> don't know enough about rvalue references to say whether this is the
> case.

I believe it is the case.

An rvalue-reference can only bind to an rvalue, however once it's
bound to a variable the reference *is* an lvalue, so for all intents
and purposes GDB could treat variables of rvalue-reference type
exactly the same as lvalue references, except for showing "&&" when
printing types.

For example:

struct X { };

X
f (X&& param)
{
  // param is an lvalue here!
  return param;  // return a copy
}

X
g (void)
{
  X x;
  return x;  // return a copy
 }

int main()
{
  X&& rv = f ( g () );
  // rv is an lvalue!
  X* addr = &rv;  // OK to take address
}

In this example, although the function parameter param and variable rv
are rvalue-references and bound to rvalues, they are named variables
and are lvalues.  i.e. the act of binding an rvalue reference to an
rvalue, thereby giving it a name, makes it an lvalue.

Which is why my gut feeling (having barely looked at the gdb code two
days ago) is that rvalue references don't need any special handling
different to existing TYPE_CODE_REF variables, except for "ptype"
printing "X&&" instead of "X&"

Unfortunately my first attempt at doing that didn't work, so I started
adding TYPE_CODE_RVAL_REF and handling it everywhere ... but I'm
having second thoughts.

  reply	other threads:[~2012-10-29 23:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-28 20:34 Jonathan Wakely
2012-10-29 14:54 ` Tom Tromey
2012-10-29 23:40   ` Jonathan Wakely [this message]
2012-10-30 15:05 ` Tom Tromey

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=CAH6eHdTrG8JuAxvWDXn_R+C18fZzkPetMoEY211i0318BTSMTA@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=gdb@sourceware.org \
    --cc=tromey@redhat.com \
    /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).