Patchwork [C++] PR 19618

login
register
mail settings
Submitter Paolo Carlini
Date May 24, 2013, 5:25 p.m.
Message ID <519FA273.7030001@oracle.com>
Download mbox | patch
Permalink /patch/246240/
State New
Headers show

Comments

Paolo Carlini - May 24, 2013, 5:25 p.m.
Hi,

On 05/24/2013 06:12 PM, Jason Merrill wrote:
> On 05/24/2013 10:50 AM, Paolo Carlini wrote:
>> +           || ((TREE_CODE (type) == ENUMERAL_TYPE
>> +            && (tree_int_cst_lt
>> +            (TYPE_SIZE (ENUM_UNDERLYING_TYPE (type)), w)))
>> +           || (TREE_CODE (type) == BOOLEAN_TYPE
>> +               && tree_int_cst_lt (TYPE_SIZE (type), w))))
>
> The size of the enum underlying type is the same as the size of the 
> enum itself, so I don't think you need to handle enum and bool 
> differently here.
Yeah. Sorry for wasting your time on this. I'm finishing testing the 
below then.

Thanks,
Paolo.

/////////////////////
Jason Merrill - May 24, 2013, 5:34 p.m.
OK.

Jason

Patch

Index: cp/class.c
===================================================================
--- cp/class.c	(revision 199302)
+++ cp/class.c	(working copy)
@@ -3140,9 +3140,12 @@  check_bitfield_decl (tree field)
 	  error ("zero width for bit-field %q+D", field);
 	  w = error_mark_node;
 	}
-      else if (compare_tree_int (w, TYPE_PRECISION (type)) > 0
-	       && TREE_CODE (type) != ENUMERAL_TYPE
-	       && TREE_CODE (type) != BOOLEAN_TYPE)
+      else if ((TREE_CODE (type) != ENUMERAL_TYPE
+		&& TREE_CODE (type) != BOOLEAN_TYPE
+		&& compare_tree_int (w, TYPE_PRECISION (type)) > 0)
+	       || ((TREE_CODE (type) == ENUMERAL_TYPE
+		    || TREE_CODE (type) == BOOLEAN_TYPE)
+		   && tree_int_cst_lt (TYPE_SIZE (type), w)))
 	warning (0, "width of %q+D exceeds its type", field);
       else if (TREE_CODE (type) == ENUMERAL_TYPE
 	       && (0 > (compare_tree_int
Index: testsuite/g++.dg/expr/bitfield12.C
===================================================================
--- testsuite/g++.dg/expr/bitfield12.C	(revision 0)
+++ testsuite/g++.dg/expr/bitfield12.C	(working copy)
@@ -0,0 +1,19 @@ 
+// PR c++/19618
+
+struct bset1 {
+  bool bit : sizeof(bool) * __CHAR_BIT__ + 1;  // { dg-warning "exceeds" }
+};
+
+enum E {};
+
+struct bset2 {
+  E bit : sizeof(E) * __CHAR_BIT__ + 1;        // { dg-warning "exceeds" }
+};
+
+struct bset3 {
+  bool bit : sizeof(bool) * __CHAR_BIT__;
+};
+
+struct bset4 {
+  E bit : sizeof(E) * __CHAR_BIT__;
+};