diff options
author | Pedro Alves <palves@redhat.com> | 2013-02-14 12:43:43 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2013-02-14 12:43:43 +0000 |
commit | 79ab359fe6a0740ca82c4cb9b66d368566a41a4f (patch) | |
tree | 45a994792a2dd227dbb43db909ef36e40953c491 /gdb/eval.c | |
parent | 32d784b33026d7800a88ff5b2dfc25c42140261e (diff) | |
download | gdb-79ab359fe6a0740ca82c4cb9b66d368566a41a4f.tar.gz |
Fix ptype bug actually exercised in userdef.exp
I happened to notice a bug with ptype &Ref, and found out userdef.exp
actually exercises the bug. With:
class Container
{
public:
Member m;
Member& operator* ();
};
Member& Container::operator* ()
{
return this->m;
}
And 'c' is of type Container:
(gdb) p c
$1 = {m = {z = -9192}}
(gdb) p *c
$2 = (Member &) @0x7fffffffda20: {z = -9192}
(gdb) ptype *c
type = class Member {
public:
int z;
} &
(gdb) p &*c
$3 = (Member *) 0x7fffffffda20
(gdb) ptype &*c
type = class Member {
public:
int z;
} &*
(gdb)
Notice that last print (&*c) on says the type is a pointer - that's
how you get the address behind a reference. But notice the last ptype
instead says the type of the same expression is a pointer _reference_.
This looks like a bug to me.
This patch fixes it. The issue is that we're entering the VALUE_LVAL
(x) == lval_memory branch by mistake for references. The fix is just
to swap the tests so references are checked first, like value_addr
also handles references first.
Tested on x86_64 Fedora 17.
2013-02-14 Pedro Alves <palves@redhat.com>
* eval.c (evaluate_subexp_for_address) <default_case_after_eval,
EVAL_AVOID_SIDE_EFFECTS>: Swap and handle TYPE_CODE_REF before
lval_memory.
2013-02-14 Pedro Alves <palves@redhat.com>
* gdb.cp/userdef.exp (ptype &*c): Don't expect an &.
Diffstat (limited to 'gdb/eval.c')
-rw-r--r-- | gdb/eval.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/gdb/eval.c b/gdb/eval.c index f4b39cbc2b0..d7f80e2d4f5 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -2929,12 +2929,12 @@ evaluate_subexp_for_address (struct expression *exp, int *pos, { struct type *type = check_typedef (value_type (x)); - if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x)) - return value_zero (lookup_pointer_type (value_type (x)), - not_lval); - else if (TYPE_CODE (type) == TYPE_CODE_REF) + if (TYPE_CODE (type) == TYPE_CODE_REF) return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)), not_lval); + else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x)) + return value_zero (lookup_pointer_type (value_type (x)), + not_lval); else error (_("Attempt to take address of " "value not located in memory.")); |