Re: C++ conversion status update

Pedro Alves
2015-12-16T00:21:57Z

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