aboutsummaryrefslogtreecommitdiff
path: root/gdb/c-exp.y
diff options
context:
space:
mode:
authorKeith Seitz <keiths@redhat.com>2014-04-11 14:17:17 -0700
committerKeith Seitz <keiths@redhat.com>2014-04-11 14:17:17 -0700
commit245a5f0b7429b03566eb3f57a92544218f33393c (patch)
tree3e733b578ae65a097557d0116a3c9c329bfb8678 /gdb/c-exp.y
parent32ae0d80cd430150ad9536aa160f34f504e129bc (diff)
downloadgdb-245a5f0b7429b03566eb3f57a92544218f33393c.zip
gdb-245a5f0b7429b03566eb3f57a92544218f33393c.tar.gz
gdb-245a5f0b7429b03566eb3f57a92544218f33393c.tar.bz2
Fix c++/16675 -- sizeof reference type should give the size of
the referent, not the size of the actual reference variable.
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r--gdb/c-exp.y14
1 files changed, 11 insertions, 3 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index fc79807..f39391c 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -787,14 +787,22 @@ exp : SELECTOR '(' name ')'
;
exp : SIZEOF '(' type ')' %prec UNARY
- { write_exp_elt_opcode (pstate, OP_LONG);
+ { struct type *type = $3;
+ write_exp_elt_opcode (pstate, OP_LONG);
write_exp_elt_type (pstate, lookup_signed_typename
(parse_language (pstate),
parse_gdbarch (pstate),
"int"));
- CHECK_TYPEDEF ($3);
+ CHECK_TYPEDEF (type);
+
+ /* $5.3.3/2 of the C++ Standard (n3290 draft)
+ says of sizeof: "When applied to a reference
+ or a reference type, the result is the size of
+ the referenced type." */
+ if (TYPE_CODE (type) == TYPE_CODE_REF)
+ type = check_typedef (TYPE_TARGET_TYPE (type));
write_exp_elt_longcst (pstate,
- (LONGEST) TYPE_LENGTH ($3));
+ (LONGEST) TYPE_LENGTH (type));
write_exp_elt_opcode (pstate, OP_LONG); }
;