Commit 7f5d76fb by Paolo Carlini Committed by Paolo Carlini

re PR c++/19618 (Do warn if a bit-field exceeds the size of a bool type)

/cp
2013-05-24  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/19618
	* class.c (check_bitfield_decl): Warn for bool and enum bitfields
	with width exceeding the type.

/testsuite
2013-05-24  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/19618
	* g++.dg/expr/bitfield12.C: New.

From-SVN: r199306
parent 2343af65
2013-05-24 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/19618
* class.c (check_bitfield_decl): Warn for bool and enum bitfields
with width exceeding the type.
2013-05-24 Jason Merrill <jason@redhat.com> 2013-05-24 Jason Merrill <jason@redhat.com>
PR c++/57391 PR c++/57391
......
...@@ -3140,9 +3140,12 @@ check_bitfield_decl (tree field) ...@@ -3140,9 +3140,12 @@ check_bitfield_decl (tree field)
error ("zero width for bit-field %q+D", field); error ("zero width for bit-field %q+D", field);
w = error_mark_node; w = error_mark_node;
} }
else if (compare_tree_int (w, TYPE_PRECISION (type)) > 0 else if ((TREE_CODE (type) != ENUMERAL_TYPE
&& TREE_CODE (type) != ENUMERAL_TYPE && TREE_CODE (type) != BOOLEAN_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); warning (0, "width of %q+D exceeds its type", field);
else if (TREE_CODE (type) == ENUMERAL_TYPE else if (TREE_CODE (type) == ENUMERAL_TYPE
&& (0 > (compare_tree_int && (0 > (compare_tree_int
......
2013-05-24 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/19618
* g++.dg/expr/bitfield12.C: New.
2013-05-24 Jeff Law <law@redhat.com> 2013-05-24 Jeff Law <law@redhat.com>
PR tree-optimization/57124 PR tree-optimization/57124
......
// 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__;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment