On 10/19/2017 12:38 PM, Eric Gallager wrote:
On 10/16/17, Martin Sebor <mse...@gmail.com> wrote:
On 10/16/2017 06:37 AM, Sam van Kampen via gcc-patches wrote:
..I just realised that the clang flag is -Wbitfield-enum-conversion, not
-Wenum-bitfield-conversion. Please apply the patch below instead, which
has replaced the two words to remove the inconsistency.

2017-10-16  Sam van Kampen  <sam@segfault.party>

        * c-family/c.opt: Add a warning flag for struct bit-fields
        being too small to hold enumerated types.
        * cp/class.c: Likewise.
        * doc/invoke.texi: Add documentation for said warning flag.

Index: gcc/c-family/c.opt
===================================================================
--- gcc/c-family/c.opt  (revision 253784)
+++ gcc/c-family/c.opt  (working copy)
@@ -346,6 +346,10 @@ Wframe-address
 C ObjC C++ ObjC++ Var(warn_frame_address) Warning LangEnabledBy(C ObjC
C++ ObjC++,Wall)
 Warn when __builtin_frame_address or __builtin_return_address is used
unsafely.

+Wbitfield-enum-conversion
+C++ Var(warn_bitfield_enum_conversion) Init(1) Warning
+Warn about struct bit-fields being too small to hold enumerated types.

Warning by default is usually reserved for problems that are
most likely indicative of bugs.  Does this rise to that level?
(It seems that it should be in the same class as -Wconversion).

The warning is already enabled by default; this patch just adds the
new flag controlling it. I don't think it's worth changing it away
from warning by default when it already warns by default now.

The C++ warning in its present form is considered unhelpful
by users (as evident from the bug report).  That it warns by
default is part of the problem.  GCC (in C mode), Clang, and
Intel ICC warn only for enums whose enumerators cannot fit in
the bitfield.  (In Clang the warning is in addition disabled
by default and has to be explicitly enabled.)

The suggestion is to add a two-level warning and adjust G++
to warn the same way at level 1 as other compilers do (and
to include this level in -Wall, or if it's considered
appropriate and necessary, enable it by default), and warn
as it does now only at level 2 (with that level having to
be explicitly requested).  I would further suggest to do
the same in GCC (in C mode), if only for consistency.

Martin

Reply via email to