From 245a5f0b7429b03566eb3f57a92544218f33393c Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Fri, 11 Apr 2014 14:17:17 -0700 Subject: Fix c++/16675 -- sizeof reference type should give the size of the referent, not the size of the actual reference variable. --- gdb/c-exp.y | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'gdb/c-exp.y') 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); } ; -- cgit v1.1