From 441b624e3d4b2be01deaf8156bd5ea2b39849259 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 15 Sep 2010 19:55:43 -0400 Subject: [PATCH] * decl2.c (grokbitfield): Diagnose non-integral width. From-SVN: r164321 --- gcc/cp/ChangeLog | 2 ++ gcc/cp/decl2.c | 4 ++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C | 11 +++++++++++ 4 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/scoped_enum2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 27cb326a7635..10630c26fc53 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,7 @@ 2010-09-15 Jason Merrill + * decl2.c (grokbitfield): Diagnose non-integral width. + * call.c (convert_like_real): Use the underlying type of the reference for the temporary. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index f2330554a145..63197705b327 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/ChangeLog b/gcc/testsuite/ChangeLog index b1f87446da02..486c9450674b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-09-15 Jason Merrill + + * g++.dg/cpp0x/scoped_enum2.C: New. + 2010-09-15 Eric Botcazou * 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 index 000000000000..e87b36a27322 --- /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 +};