[RFA] c++/16675 (incorrect sizeof reference types)
Keith Seitz
keiths@redhat.com
Fri Mar 21 18:25:00 GMT 2014
Hi,
This bug is easily demonstrated (from the bugzilla):
typedef unsigned char a4[4];
a4 p1;
a4& p2 = p1;
std::cout<<sizeof(p2);
(gdb) p sizeof (p2)
$1 = 8
Yet if you run the thing, it prints "4".
Regarding the sizeof operator and references, $5.3.3/2 of the n3290
draft says, "When applied to a reference or a reference type, the result
is the size of the referenced type."
The following patch implements this change in the c++ parser (when type
names are used) and expression evaluator (when variable names are used).
No regressions on native x86_64-linux or native-gdbserver.
Keith
ChangeLog
2014-03-20 Keith Seitz <keiths@redhat.com>
PR c++/16675
* c-exp.y (exp : SIZEOF '(' type ')'): Handle reference types.
* eval.c (evaluate_subexp_for_sizeof): Refactor and handle
reference types.
testsuite/ChangeLog
2014-03-20 Keith Seitz <keiths@redhat.com>
PR c++/16675
* gdb.cp/cpsizeof.exp: New file.
* gdb.cp/cpsizeof.cc: New file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 16675.patch
Type: text/x-patch
Size: 6544 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20140321/0b6d67f7/attachment.bin>
More information about the Gdb-patches
mailing list