]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* decl2.c (grokbitfield): Diagnose non-integral width.
authorJason Merrill <jason@redhat.com>
Wed, 15 Sep 2010 23:55:43 +0000 (19:55 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 15 Sep 2010 23:55:43 +0000 (19:55 -0400)
From-SVN: r164321

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C [new file with mode: 0644]

index 27cb326a7635eea7c09201f13f1c0eeb77f7d2e3..10630c26fc532c683631d8f85461b50164e1c1d7 100644 (file)
@@ -1,5 +1,7 @@
 2010-09-15  Jason Merrill  <jason@redhat.com>
 
+       * decl2.c (grokbitfield): Diagnose non-integral width.
+
        * call.c (convert_like_real): Use the underlying type of the
        reference for the temporary.
 
index f2330554a145668e1ed335f4363b29ba1249b16e..63197705b3271cacdf9150161615c0255c201fc0 100644 (file)
@@ -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);
index b1f87446da02a1a73d4dff0a5f97281c5539bbaf..486c9450674b93c61f27b72bb216bb429707b6d8 100644 (file)
@@ -1,3 +1,7 @@
+2010-09-15  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/scoped_enum2.C: New.
+
 2010-09-15  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc.c-torture/compile/20100915-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C b/gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C
new file mode 100644 (file)
index 0000000..e87b36a
--- /dev/null
@@ -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
+};