diff mbox

C++0x PATCH to grokbitfield

Message ID 4C915DCB.4080907@redhat.com
State New
Headers show

Commit Message

Jason Merrill Sept. 15, 2010, 11:59 p.m. UTC
We were failing to diagnose use of a scoped enum as a bit-field width.

Tested x86_64-pc-linux-gnu, applied to trunk.
diff mbox

Patch

commit bb4f84e102b0828f0318c1b64dbb2025d5b4acc4
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Sep 15 15:25:12 2010 -0400

    	* decl2.c (grokbitfield): Diagnose non-integral width.

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index f233055..63197705 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1066,6 +1066,10 @@  grokbitfield (const cp_declarator *declarator,
 
   if (width != error_mark_node)
     {
+      /* The width must be an integer type.  */
+      if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width)))
+	error ("width of bit-field %qD has non-integral type %qT", value,
+	       TREE_TYPE (width));
       constant_expression_warning (width);
       DECL_INITIAL (value) = width;
       SET_DECL_C_BIT_FIELD (value);
diff --git a/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C b/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C
new file mode 100644
index 0000000..e87b36a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C
@@ -0,0 +1,11 @@ 
+// { dg-options -std=c++0x }
+
+enum class E { e = 10 };
+enum E2 { e2 = 10 };
+
+struct C {
+  int arr[E::e];    // { dg-error "non-integral type" }
+  int arr2[E2::e2]; // OK
+  int i: E::e;	    // { dg-error "non-integral type" }
+  int i2: E2::e2;   // OK
+};