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] Default initialize enum flags to 0


On 02/20/2017 09:45 PM, Simon Marchi wrote:
> ... so that we don't need to do it manually, and potentially forget.
> For example, this allows to do:
> 
>   my_flags flags;
> 
>   ...
> 
>   flags |= some_flag;
> 
> gdb/ChangeLog:
> 
> 	* common/enum-flags.h (enum_flags::enum_flags): Initialize
> 	m_enum_value to 0 in default constructor.

Not sure I really like this.  3 reasons off hand.  None are
very strong, but let me put them out nonetheless:

#1 - I have some desire of creating a "gdb/gnu template library" dir
and moving these utilities there, in order to share them with more
projects (e.g., gcc, and who knows, gold and who knows other parts
of binutils that might want to convert to C++ in the future), and
it'd be nice to keep the type behaving the same in C and C++
modes (that's why I had left the !__cplusplus branch in
the file).  [1].

#2 - The other reason is that it's nice IMO to leave enums and enum flags
easily interchangeable -- i.e., make them behave as close as possible.
Having one be default initialized, and the other value initialized
means that when changing variables from one type to the other
one needs to consider that aspect.

#3 - Default initializing to zero can hide bugs that would otherwise
be caught with -Winitialized.

[1] - Trevor expressed something similar before too [2]:
https://sourceware.org/ml/gdb-patches/2016-11/msg00114.html

[2] - Yes, I need to find some time to post a v2 of that
      series.  :-P  (It's baking slowing on my github.)

Thanks,
Pedro Alves


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