diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2003-04-22 12:28:51 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2003-04-22 12:28:51 +0000 |
commit | ad27e65a227c17f460b3c0d4cb42d87453110351 (patch) | |
tree | cf90264870e497c09eb9a301d929a33fbb4c69f2 /gcc/ginclude | |
parent | 834277a89aec821dc2d4da5ee03a6f0ca59b2819 (diff) | |
download | gcc-ad27e65a227c17f460b3c0d4cb42d87453110351.zip gcc-ad27e65a227c17f460b3c0d4cb42d87453110351.tar.gz gcc-ad27e65a227c17f460b3c0d4cb42d87453110351.tar.bz2 |
stddef.h: Provide C++ safe offsetof.
.: * ginclude/stddef.h: Provide C++ safe offsetof.
testsuite:
* g++.dg/other/offsetof2.C: New test.
From-SVN: r65936
Diffstat (limited to 'gcc/ginclude')
-rw-r--r-- | gcc/ginclude/stddef.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h index f1046f4..ad091ea 100644 --- a/gcc/ginclude/stddef.h +++ b/gcc/ginclude/stddef.h @@ -410,8 +410,14 @@ typedef __WINT_TYPE__ wint_t; #ifdef _STDDEF_H /* 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. */ +#define offsetof(TYPE, MEMBER) (reinterpret_cast <size_t> \ + (&reinterpret_cast <char &>(static_cast <TYPE *> (0)->MEMBER))) +#endif /* C++ */ #endif /* _STDDEF_H was defined this time */ |