Re: [C++ Patch / RFC] PR 51242

2013-02-15 Thread Paolo Carlini

On 02/15/2013 06:40 PM, Jason Merrill wrote:
The patch is OK.  To deal with the warning, I would suggest putting 
the constrained type somewhere other than ENUM_UNDERLYING_TYPE that's 
shared between enums with fixed and non-fixed underlying types; having 
it in ENUM_UNDERLYING_TYPE isn't really correct anyway.
Ok, thanks. Then I committed the below and I'm keeping the PR open for 
the warning.


Thanks again,
Paolo.

///
/cp
2013-02-15  Jonathan Wakely  
Paolo Carlini  

PR c++/51242
* decl2.c (grokbitfield): Allow scoped enumeration types.

/testsuite
2013-02-15  Jonathan Wakely  
Paolo Carlini  

PR c++/51242
* g++.dg/cpp0x/enum23.C: New.

Index: cp/decl2.c
===
--- cp/decl2.c  (revision 196095)
+++ cp/decl2.c  (working copy)
@@ -1028,7 +1028,7 @@ grokbitfield (const cp_declarator *declarator,
   if (TREE_CODE (value) == VOID_TYPE)
 return void_type_node;
 
-  if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (value))
+  if (!INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value))
   && (POINTER_TYPE_P (value)
   || !dependent_type_p (TREE_TYPE (value
 {
Index: testsuite/g++.dg/cpp0x/enum23.C
===
--- testsuite/g++.dg/cpp0x/enum23.C (revision 0)
+++ testsuite/g++.dg/cpp0x/enum23.C (working copy)
@@ -0,0 +1,9 @@
+// PR c++/51242
+// { dg-do compile { target c++11 } }
+
+enum class MyEnum { A = 1 };
+
+struct MyClass
+{
+  MyEnum Field1 : 3; // { dg-bogus "warning: 'MyClass::Field1' is too small" 
"" { xfail *-*-* } }
+};


Re: [C++ Patch / RFC] PR 51242

2013-02-15 Thread Jason Merrill
The patch is OK.  To deal with the warning, I would suggest putting the 
constrained type somewhere other than ENUM_UNDERLYING_TYPE that's shared 
between enums with fixed and non-fixed underlying types; having it in 
ENUM_UNDERLYING_TYPE isn't really correct anyway.


Jason


[C++ Patch / RFC] PR 51242

2012-11-26 Thread Paolo Carlini

Hi,

this PR is about the rejection (in C++11 mode of course) of:

enum class MyEnum { A = 1 };

struct MyClass
{
  MyEnum Field1 : 3;
};


whereas the corresponding unscoped enum case already works. As noticed 
by Jon, it seems that the below straightforward patchlet is enough to 
solve the problem but then we have a warning issue:


51242.C:5:19: warning: ‘MyClass::Field1’ is too small to hold all values 
of ‘enum class MyEnum’ [enabled by default]


which is easily explained: the underlying type is fixed (to an implicit 
int type), thus in finish_enum_value_list, fixed_underlying_type_p is 
true and the code "restricting" the ENUM_UNDERLYING_TYPE for diagnostic 
purposes doesn't run. In other terms, we warn for the same reason we for 
example -Wnarrowing warn (before erroring out) for:


enum class Code {
  SUCCESS = 0
};

Code a;

short r[] = {a};


That seems intended, but especially annoying in the bitfield case. An 
idea could be giving a name to the "too small to hold all values" 
warning and making possible disabling it. What do you suggest?


Thanks!
Paolo.
Index: decl2.c
===
--- decl2.c (revision 193814)
+++ decl2.c (working copy)
@@ -1030,7 +1030,7 @@ grokbitfield (const cp_declarator *declarator,
   if (TREE_CODE (value) == VOID_TYPE)
 return void_type_node;
 
-  if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (value))
+  if (!INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value))
   && (POINTER_TYPE_P (value)
   || !dependent_type_p (TREE_TYPE (value
 {