summaryrefslogtreecommitdiff
path: root/gcc/ginclude
diff options
context:
space:
mode:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-02 14:30:53 +0000
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-02 14:30:53 +0000
commit64658f9a22d24e65fa12749a2861192cf0bf3b12 (patch)
treec7270cd5c87616a67700ed7086e69da94972c8fc /gcc/ginclude
parentc364acf4fc31d31a9bcccf9a38e0b57daffb1d43 (diff)
downloadgcc-64658f9a22d24e65fa12749a2861192cf0bf3b12.tar.gz
PR c++/11072
* ginclude/stddef.h (offsetof): Remove cast to 'char &'. Explain why. testsuite: PR c++/11072 * g++.dg/other/offsetof2.C: XFAIL. * g++.dg/other/offsetof5.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@68831 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ginclude')
-rw-r--r--gcc/ginclude/stddef.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
index ad091ea1383..d19d78a3140 100644
--- a/gcc/ginclude/stddef.h
+++ b/gcc/ginclude/stddef.h
@@ -409,16 +409,26 @@ typedef __WINT_TYPE__ wint_t;
#ifdef _STDDEF_H
-/* Offset of member MEMBER in a struct of type TYPE. */
+/* Offset of member MEMBER in a struct of type TYPE. */
#ifndef __cplusplus
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#else /* C++ */
-/* The reference cast is necessary to thwart an operator& that might
- be applicable to MEMBER's type. See DR 273 for details. */
+#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> \
- (&reinterpret_cast <char &>(static_cast <TYPE *> (0)->MEMBER)))
+ (&static_cast<TYPE *> (0)->MEMBER))
#endif /* C++ */
-
#endif /* _STDDEF_H was defined this time */
#endif /* !_STDDEF_H && !_STDDEF_H_ && !_ANSI_STDDEF_H && !__STDDEF_H__