Commit 42c244d8 by Richard Henderson Committed by Richard Henderson

cp-tree.def (OFFSETOF_EXPR): New.

        * cp-tree.def (OFFSETOF_EXPR): New.
        * parser.c (cp_parser_builtin_offsetof): Either built an
        OFFSETOF_EXPR, or call fold_offsetof immediately.
        * pt.c (tsubst_expr): Handle OFFSETOF_EXPR.

From-SVN: r86679
parent a2fddff9
2004-08-27 Richard Henderson <rth@redhat.com>
* cp-tree.def (OFFSETOF_EXPR): New.
* parser.c (cp_parser_builtin_offsetof): Either built an
OFFSETOF_EXPR, or call fold_offsetof immediately.
* pt.c (tsubst_expr): Handle OFFSETOF_EXPR.
2004-08-27 Nathan Sidwell <nathan@codesourcery.com> 2004-08-27 Nathan Sidwell <nathan@codesourcery.com>
* call.c (validate_conversion_obstack): Replace * call.c (validate_conversion_obstack): Replace
......
...@@ -282,6 +282,9 @@ DEFTREECODE (TAG_DEFN, "tag_defn", 'e', 0) ...@@ -282,6 +282,9 @@ DEFTREECODE (TAG_DEFN, "tag_defn", 'e', 0)
DEFTREECODE (TINST_LEVEL, "TINST_LEVEL", 'x', 0) DEFTREECODE (TINST_LEVEL, "TINST_LEVEL", 'x', 0)
/* Represents an 'offsetof' expression during template expansion. */
DEFTREECODE (OFFSETOF_EXPR, "offsetof_expr", 'e', 1)
/* /*
Local variables: Local variables:
mode:c mode:c
......
...@@ -5876,18 +5876,12 @@ cp_parser_builtin_offsetof (cp_parser *parser) ...@@ -5876,18 +5876,12 @@ cp_parser_builtin_offsetof (cp_parser *parser)
} }
success: success:
/* We've finished the parsing, now finish with the semantics. At present /* If we're processing a template, we can't finish the semantics yet.
we're just mirroring the traditional macro implementation. Better Otherwise we can fold the entire expression now. */
would be to do the lowering of the ADDR_EXPR to flat pointer arithmetic if (processing_template_decl)
here rather than in build_x_unary_op. */ expr = build1 (OFFSETOF_EXPR, size_type_node, expr);
else
expr = (build_reinterpret_cast expr = fold_offsetof (expr);
(build_reference_type (cp_build_qualified_type
(char_type_node,
TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)),
expr));
expr = build_x_unary_op (ADDR_EXPR, expr);
expr = build_reinterpret_cast (size_type_node, expr);
failure: failure:
parser->integral_constant_expression_p = save_ice_p; parser->integral_constant_expression_p = save_ice_p;
......
...@@ -8092,6 +8092,11 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) ...@@ -8092,6 +8092,11 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
tsubst (TREE_TYPE (t), args, complain, NULL_TREE); tsubst (TREE_TYPE (t), args, complain, NULL_TREE);
break; break;
case OFFSETOF_EXPR:
t = tsubst_copy_and_build (TREE_OPERAND (t, 0), args, complain,
in_decl, false);
return fold_offsetof (t);
default: default:
if (!STATEMENT_CODE_P (TREE_CODE (t))) if (!STATEMENT_CODE_P (TREE_CODE (t)))
return tsubst_copy_and_build (t, args, complain, in_decl, return tsubst_copy_and_build (t, args, complain, in_decl,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment