aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>2004-08-27 14:48:12 -0700
committerRichard Henderson <rth@gcc.gnu.org>2004-08-27 14:48:12 -0700
commit42c244d8479bf2900995626586b8ec25b9b3eb5a (patch)
treef506b144421d7b9eb085b0ca871f275af2238424 /gcc/cp
parenta2fddff9be09cf004aa687e489d7ae04f237a901 (diff)
downloadgcc-42c244d8479bf2900995626586b8ec25b9b3eb5a.zip
gcc-42c244d8479bf2900995626586b8ec25b9b3eb5a.tar.gz
gcc-42c244d8479bf2900995626586b8ec25b9b3eb5a.tar.bz2
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
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/cp-tree.def3
-rw-r--r--gcc/cp/parser.c18
-rw-r--r--gcc/cp/pt.c5
4 files changed, 21 insertions, 12 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a4796a1..afd820f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+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>
* call.c (validate_conversion_obstack): Replace
diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index d3629fd..02afea9 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -282,6 +282,9 @@ DEFTREECODE (TAG_DEFN, "tag_defn", 'e', 0)
DEFTREECODE (TINST_LEVEL, "TINST_LEVEL", 'x', 0)
+/* Represents an 'offsetof' expression during template expansion. */
+DEFTREECODE (OFFSETOF_EXPR, "offsetof_expr", 'e', 1)
+
/*
Local variables:
mode:c
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 9d5e18b..c0d5227 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -5876,18 +5876,12 @@ cp_parser_builtin_offsetof (cp_parser *parser)
}
success:
- /* We've finished the parsing, now finish with the semantics. At present
- we're just mirroring the traditional macro implementation. Better
- would be to do the lowering of the ADDR_EXPR to flat pointer arithmetic
- here rather than in build_x_unary_op. */
-
- expr = (build_reinterpret_cast
- (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);
+ /* If we're processing a template, we can't finish the semantics yet.
+ Otherwise we can fold the entire expression now. */
+ if (processing_template_decl)
+ expr = build1 (OFFSETOF_EXPR, size_type_node, expr);
+ else
+ expr = fold_offsetof (expr);
failure:
parser->integral_constant_expression_p = save_ice_p;
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c198118..a979e83 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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);
break;
+ case OFFSETOF_EXPR:
+ t = tsubst_copy_and_build (TREE_OPERAND (t, 0), args, complain,
+ in_decl, false);
+ return fold_offsetof (t);
+
default:
if (!STATEMENT_CODE_P (TREE_CODE (t)))
return tsubst_copy_and_build (t, args, complain, in_decl,