summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-05-24 17:37:41 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-05-24 17:37:41 +0000
commit7345779f98b210fbe5d641367fb746a19d255d26 (patch)
treed61337f07687efcd2340ad1335a2c5ee0514ab86
parent65a8f1a1cd31f5b564a7e41e9146c638aaeb0942 (diff)
downloadgcc-7345779f98b210fbe5d641367fb746a19d255d26.tar.gz
/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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@199306 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/class.c9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/expr/bitfield12.C19
4 files changed, 36 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 585ab73bf40..7b02b8b3b5b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+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>
PR c++/57391
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 94ae5672548..d6684cfd68b 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8c2e2939561..a0278d5fe33 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+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>
PR tree-optimization/57124
diff --git a/gcc/testsuite/g++.dg/expr/bitfield12.C b/gcc/testsuite/g++.dg/expr/bitfield12.C
new file mode 100644
index 00000000000..3ae88ca191c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/expr/bitfield12.C
@@ -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__;
+};