This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: C++ conversion status update
- From: Pedro Alves <palves at redhat dot com>
- To: Simon Marchi <simon dot marchi at polymtl dot ca>, "Jose E. Marchesi" <jose dot marchesi at oracle dot com>
- Cc: Yao Qi <qiyaoltc at gmail dot com>, "gdb at sourceware dot org" <gdb at sourceware dot org>
- Date: Wed, 16 Dec 2015 00:21:51 +0000
- Subject: Re: C++ conversion status update
- Authentication-results: sourceware.org; auth=none
- References: <565460FB dot 6070103 at redhat dot com> <86zixdnlfg dot fsf at gmail dot com> <566F13D4 dot 9000900 at redhat dot com> <877fkglytf dot fsf at oracle dot com> <CAFXXi0mju2QKzp40emJWqxkRrhWMLK77nBOLty-ub+5oGKaH3A at mail dot gmail dot com> <5670AE0A dot 20201 at redhat dot com>
Forgot to mention that this compiles down to the same as offsetof at -O2.
On 12/16/2015 12:19 AM, Pedro Alves wrote:
> diff --git a/gdb/common/vec.h b/gdb/common/vec.h
> index 6189283..a188b02 100644
> --- a/gdb/common/vec.h
> +++ b/gdb/common/vec.h
> @@ -437,13 +437,23 @@ DEF_VEC_FUNC_O(T) \
> DEF_VEC_ALLOC_FUNC_O(T) \
> struct vec_swallow_trailing_semi
>
> +/* Avoid offsetof (or its usual C implementation) as it triggers
> + -Winvalid-offsetof warnings with enum_flags types with G++ <= 4.4,
> + even though those types are memcpyable. This requires allocating a
> + dummy local VEC in all routines that use this, but that has the
> + advantage that it only works if T is default constructible, which
> + is exactly a check we want, to keep C compatibility. */
> +#define vec_offset(T, VPTR) ((size_t) ((char *) &(VPTR)->vec - (char *) VPTR))
Thanks,
Pedro Alves