diff options
author | nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-04-22 12:28:51 +0000 |
---|---|---|
committer | nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-04-22 12:28:51 +0000 |
commit | 8f95801871f9a18fcefd6868c6b709425e744d2b (patch) | |
tree | cf90264870e497c09eb9a301d929a33fbb4c69f2 /gcc/ginclude/stddef.h | |
parent | 09258369da6ac4b9bdbcc2902e258b4b67e7c87b (diff) | |
download | gcc-8f95801871f9a18fcefd6868c6b709425e744d2b.tar.gz |
.:
* ginclude/stddef.h: Provide C++ safe offsetof.
testsuite:
* g++.dg/other/offsetof2.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@65936 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ginclude/stddef.h')
-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 f1046f44bb1..ad091ea1383 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 */ |