This is the mail archive of the mailing list for the GCC 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]

[patch, c++] Add a warning flag for the enum bit-field declaration warning in bug #61414.

This patch adds a warning flag for the warning described in bug report
#61414. My proposed warning flag is -Wenum-bitfield-conversion, which
corresponds with the warning flag that clang has for a similar warning.

2017-10-16  Sam van Kampen  <>

	* 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 253769)
+++ gcc/c-family/c.opt	(working copy)
@@ -500,6 +500,10 @@ Wenum-compare
 C ObjC C++ ObjC++ Var(warn_enum_compare) Init(-1) Warning LangEnabledBy(C ObjC,Wall || Wc++-compat)
 Warn about comparison of different enum types.
+C++ Var(warn_enum_bitfield_conversion) Init(1) Warning
+Warn about struct bit-fields being too small to hold enumerated types.
 C ObjC C++ ObjC++
 ; Documented in common.opt
Index: gcc/cp/class.c
--- gcc/cp/class.c	(revision 253769)
+++ gcc/cp/class.c	(working copy)
@@ -3278,10 +3278,11 @@ check_bitfield_decl (tree field)
 		   && tree_int_cst_lt (TYPE_SIZE (type), w)))
 	warning_at (DECL_SOURCE_LOCATION (field), 0,
 		    "width of %qD exceeds its type", field);
-      else if (TREE_CODE (type) == ENUMERAL_TYPE
+      else if (warn_enum_bitfield_conversion
+	       && TREE_CODE (type) == ENUMERAL_TYPE
 	       && (0 > (compare_tree_int
-	warning_at (DECL_SOURCE_LOCATION (field), 0,
+	warning_at (DECL_SOURCE_LOCATION (field), OPT_Wenum_bitfield_conversion,
 		    "%qD is too small to hold all values of %q#T",
 		    field, type);
Index: gcc/doc/invoke.texi
--- gcc/doc/invoke.texi	(revision 253769)
+++ gcc/doc/invoke.texi	(working copy)
@@ -277,8 +277,8 @@ Objective-C and Objective-C++ Dialects}.
 -Wno-discarded-qualifiers  -Wno-discarded-array-qualifiers @gol
 -Wno-div-by-zero  -Wdouble-promotion @gol
 -Wduplicated-branches  -Wduplicated-cond @gol
--Wempty-body  -Wenum-compare  -Wno-endif-labels  -Wexpansion-to-defined @gol
--Werror  -Werror=*  -Wextra-semi  -Wfatal-errors @gol
+-Wempty-body  -Wenum-bitfield-conversion  -Wenum-compare  -Wno-endif-labels @gol
+-Wexpansion-to-defined  -Werror  -Werror=*  -Wextra-semi  -Wfatal-errors @gol
 -Wfloat-equal  -Wformat  -Wformat=2 @gol
 -Wno-format-contains-nul  -Wno-format-extra-args  @gol
 -Wformat-nonliteral -Wformat-overflow=@var{n} @gol
@@ -6126,6 +6126,12 @@ Warn when an expression is casted to its own type.
 Warn if an empty body occurs in an @code{if}, @code{else} or @code{do
 while} statement.  This warning is also enabled by @option{-Wextra}.
+@item -Wenum-bitfield-conversion
+@opindex Wenum-bitfield-conversion
+@opindex Wno-enum-bitfield-conversion
+Warn about a bit-field potentially being too small to hold all values
+of an enumerated type. This warning is enabled by default.
 @item -Wenum-compare
 @opindex Wenum-compare
 @opindex Wno-enum-compare

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