aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/expr.c
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2004-05-28 23:34:39 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2004-05-28 23:34:39 +0000
commitb3dd05b10a8318c7af07941d3b13b75b5c4f5683 (patch)
treefc43bc68b07b9156872a885e6b8eb0ad184a0c72 /gcc/cp/expr.c
parent5182fafe486b98e95bd51d2d665a2a18f397fbe4 (diff)
downloadgcc-b3dd05b10a8318c7af07941d3b13b75b5c4f5683.zip
gcc-b3dd05b10a8318c7af07941d3b13b75b5c4f5683.tar.gz
gcc-b3dd05b10a8318c7af07941d3b13b75b5c4f5683.tar.bz2
re PR c++/15471 (Incorrect member pointer offsets in anonymous structs/unions)
PR c++/15471 * typeck.c (unary_complex_lvalue): Use context_for_name_lookup when determining the scope to use for a pointer to member. (lookup_anon_field): Give it external linkage. * cp-tree.h (lookup_anon_field): Declare it. * expr.c (cplus_expand_constant): Use it. From-SVN: r82401
Diffstat (limited to 'gcc/cp/expr.c')
-rw-r--r--gcc/cp/expr.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/gcc/cp/expr.c b/gcc/cp/expr.c
index e12c6a4..466d984 100644
--- a/gcc/cp/expr.c
+++ b/gcc/cp/expr.c
@@ -51,8 +51,21 @@ cplus_expand_constant (tree cst)
member = PTRMEM_CST_MEMBER (cst);
if (TREE_CODE (member) == FIELD_DECL)
- /* Find the offset for the field. */
- cst = fold (build_nop (type, byte_position (member)));
+ {
+ /* Find the offset for the field. */
+ cst = byte_position (member);
+ while (!same_type_p (DECL_CONTEXT (member),
+ TYPE_PTRMEM_CLASS_TYPE (type)))
+ {
+ /* The MEMBER must have been nestled within an
+ anonymous aggregate contained in TYPE. Find the
+ anonymous aggregate. */
+ member = lookup_anon_field (TYPE_PTRMEM_CLASS_TYPE (type),
+ DECL_CONTEXT (member));
+ cst = size_binop (PLUS_EXPR, cst, byte_position (member));
+ }
+ cst = fold (build_nop (type, cst));
+ }
else
{
tree delta;