summaryrefslogtreecommitdiff
path: root/gcc/ginclude
diff options
context:
space:
mode:
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2003-12-16 16:09:23 +0000
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>2003-12-16 16:09:23 +0000
commit30b87eb66b0a23a972f6ed649614858b85470dff (patch)
tree2b4a4284864e77f0905c40d1a718bb9eb360f8ac /gcc/ginclude
parentf0fb2d8d67653482f94a0e41d763622893714cfa (diff)
downloadgcc-30b87eb66b0a23a972f6ed649614858b85470dff.tar.gz
PR c++/13275
* c-common.h (enum rid): Add RID_OFFSETOF. * c-parser.in (rid_to_yy): Ignore RID_OFFSETOF. * ginclude/stddef.h (offsetof): Reimplement for C++, using __offsetof__. * doc/extend.texi: Document __offsetof__. PR c++/13275 * lex.c (reswords): Add "__offsetof" and "__offsetof__". * parser.c (cp_parser): Add in_offsetof_p. (cp_parser_new): Initialize it. (cp_parser_primary_expression): Handle __offsetof__ (...). (cp_parser_postfix_expression): Allow casts to pointer type and uses of "->" in a constant expression if implementing offsetof. (cp_parser_unary_expression): Allow the use of "&" in a constant expression if implementing offsetof. PR c++/13275 * g++.dg/other/offsetof2.C: Remove XFAIL. * g++.dg/parse/offsetof1.C: New test. * g++.gd/parse/offsetof2.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@74702 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ginclude')
-rw-r--r--gcc/ginclude/stddef.h21
1 files changed, 6 insertions, 15 deletions
diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
index d19d78a3140..1bb3e90bc9b 100644
--- a/gcc/ginclude/stddef.h
+++ b/gcc/ginclude/stddef.h
@@ -413,21 +413,12 @@ typedef __WINT_TYPE__ wint_t;
#ifndef __cplusplus
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#else
-/* In C++ a POD type can have a user defined address-of operator, and
- that will break offsetof. C++ core defect 273 addresses this and
- claims that reinterpret_casts to char & type are sufficient to
- overcome this problem.
-
- (reinterpret_cast <size_t>
- (&reinterpret_cast <char &>(static_cast <TYPE *> (0)->MEMBER)))
-
- But, such casts are not permitted in integral constant expressions,
- which offsetof is supposed to be.
-
- It appears that offsetof is unimplementable in C++ without a
- compiler extension. */
-#define offsetof(TYPE, MEMBER) (reinterpret_cast <size_t> \
- (&static_cast<TYPE *> (0)->MEMBER))
+/* The cast to "char &" below avoids problems with user-defined
+ "operator &", which can appear in a POD type. */
+#define offsetof(TYPE, MEMBER) \
+ (__offsetof__ (reinterpret_cast <size_t> \
+ (&reinterpret_cast <char &> \
+ (static_cast<TYPE *> (0)->MEMBER))))
#endif /* C++ */
#endif /* _STDDEF_H was defined this time */