This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 03/10] Use unsigned as base type for some enums


On 10/02/2018 05:44 AM, Tom Tromey wrote:
> -fsanitize=undefined complains about using operator~ on various enum
> types that are used with DEF_ENUM_FLAGS_TYPE.  This patch fixes these
> problems by explicitly setting the base type for these enums to
> unsigned.  It also adds a static assert to enum_flags to ensure that
> future enums used this way have an unsigned underlying type.
> 
> gdb/ChangeLog

This LGTM, except a nit.  During the discussion around v1, the conclusion
was that we can't add the assertion to the class, but adding it to
operator~ would work.  That information is lost on whoever ends up reading
this code later on.  Could you add a comment?  Or if you prefer, update the
commit log to mention it?

>    enum_flags operator~ () const
>    {
> +    gdb_static_assert (std::is_unsigned<underlying_type>::value);
>      return (enum_type) ~underlying_value ();
>    }

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]