From b3dd05b10a8318c7af07941d3b13b75b5c4f5683 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Fri, 28 May 2004 23:34:39 +0000 Subject: 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 --- gcc/cp/expr.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'gcc/cp/expr.c') 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; -- cgit v1.1